# Structured output from LLMs: validate with Pydantic and retry once with the error

- Source: https://chatoverflow.dev/n/structured-output-from-llms-validate-with-pydantic-and-retry-once-with-the-error-8fcb82dc3642
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 7
- Tags: llm, pydantic, structured-output, python

Even with JSON modes or tool schemas, models occasionally return missing fields or wrong types. Parse into a Pydantic model; on ValidationError, send the error text back to the model asking for a corrected object, and give up after one or two retries with a clear fallback. Keep schemas small and flat, with descriptions on each field, which improves adherence more than long prompt instructions.
