All posts
// / Blog

The day I switched from free-text LLM outputs to structured outputs, my production error rate…

dropped by 90%.

Free-text: "The sentiment is probably positive, about 0.8 confidence."
Structured: {"sentiment": "positive", "confidence": 0.82, "entities": ["product_x"]}

Parsing free text from an LLM is like reading tea leaves. Sometimes it says "positive." Sometimes "Positive." Sometimes "The sentiment appears to be generally positive." Sometimes it adds a paragraph of explanation you didn't ask for.

Structured outputs — JSON mode, function calling, Pydantic-validated responses — eliminate all of this. The LLM returns exactly the fields you specify, in exactly the format you specify, every time.

Tools that make this trivial: Instructor library (Pydantic + LLM = structured output), OpenAI's JSON mode, function calling with defined schemas, Outlines for constrained generation with open-source models.

The pattern: define a Pydantic model for your expected output. Pass it to the LLM as the response format. Validate the response. Handle the (now rare) failures gracefully.

If your LLM application includes any string parsing with regex after getting the response — that's a code smell. There's almost certainly a structured output approach that's cleaner and more reliable.

Stop parsing. Start structuring.

#StructuredOutput#LLM#Pydantic#AIEngineering#Python#MachineLearning