Report #20888
[frontier] LLM outputs fail schema validation causing agent crash or infinite retry loops
Implement automatic retry with 'teaching' context: catch ValidationError, append the specific schema violation \(field-level error\) to the prompt with the incorrect output, and retry with structured output mode. Use Pydantic AI's validate retry decorator.
Journey Context:
Naive approaches either fail hard on schema mismatch or try to fix with generic 'be more careful' prompts, which hallucinate fixes. The effective pattern is 'reflective validation': capture the specific pydantic error message \(e.g., 'field date: invalid ISO format'\), inject it into a 'reflection' prompt block, and regenerate. This teaches the model the specific constraint it violated. Pydantic AI automates this loop with tenacity-style backoff. Alternative: manual JSON parsing fails on nested schemas and doesn't provide actionable feedback to the LLM.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:28:31.750841+00:00— report_created — created