Resolved

AI content generation causes uncontrolled file size growth

AI/ML
Content Generation
NLP
Automation
Documentation
Refactoring
Text Processing
Prompt Engineering

Automated content refinement system doubles file sizes by adding instead of replacing text | Fixes evaluator feedback loops that create expansion death spirals in generated documentation

Working with an AI-driven content generation system (likely Python-based with custom evaluator/feedback loops) to refine technical documentation. The system uses prompt engineering to iteratively improve content quality, with a focus on maintaining concise, insightful documentation rather than expanding file sizes.

Issue

The automated content generation system exhibited uncontrolled file size growth during iterative refinement, with documentation files doubling in size between iterations (2,282 bytes → 4,728 bytes). This “expansion death spiral” occurred when evaluator feedback triggered additive changes rather than refinements, specifically when requests like “Clarify the purpose of type hints” resulted in new sentences being appended instead of existing content being improved.

Culprit

The root cause was flawed prompt engineering in prompts/evaluator_prompt.txt that used expansionary language (“add more detail”, “clarify”) rather than replacement-focused instructions. The evaluator’s mental model treated “better content” as equivalent to “more content”, causing:

  1. Original text: "with type hints defining the input and output schema"
  2. Feedback interpretation: Append explanatory sentence
  3. Result: Two sentences where one should have been refined

This created a compounding effect where each iteration added 100-200% more content while only marginally improving quality.

Solution

Prompt Engineering Fix

Modified the evaluator prompt to enforce the REPLACE NOT ADD principle with three key changes:

  1. Critical Principle Section (added to evaluator_prompt.txt):
⚠️ CRITICAL PRINCIPLE: Path to EXCELLENT is through REFINEMENT, not EXPANSION
- DON'T ask to "add more detail" or "add more context"
- INSTEAD ask to "REPLACE sentence X with a more insightful version that explains Y"
  1. Feedback Examples Transformation:
- ❌ BAD: "Clarify the purpose of type hints"
- ✅ GOOD: "In paragraph 2, REPLACE 'type hints defining schema' with 'type hints enable automatic schema generation, making tools discoverable by AI models'"
  1. Lexical Replacement Rules: All instances of:
  • “Add” → “Replace”
  • “Clarify” → “Refine”
  • “More detail” → “More insightful version”

Expected Behavioral Change

Before (Problematic):

Original: "with type hints defining the input and output schema"
Feedback: "Clarify the purpose of type hints"
Result: "with type hints defining the input and output schema. Type hints are crucial because..."

After (Fixed):

Original: "with type hints defining the input and output schema"
Feedback: "REPLACE 'type hints defining schema' with 'type hints enabling automatic schema generation for AI discovery'"
Result: "with type hints enabling automatic schema generation for AI discovery"

Verification Metrics

The fix includes a testing checklist requiring:

  1. Evaluator feedback must use “REPLACE” terminology
  2. File sizes must stabilize or decrease across ≥3 iterations
  3. Content quality ratings must improve from GOOD→EXCELLENT without length increases
  4. No new sentences should be added unless replacing ≥2 existing sentences