Tip: Use Structured Outputs to Eliminate JSON Parsing Headaches
One of the fastest improvements you can make to any LLM-powered application is switching from free-form text outputs to structured, schema-validated responses. The difference in reliability is dramatic.
When a model returns unstructured text and you parse it with regex or manual string manipulation, you are building a system that breaks on any variation in phrasing or formatting. Models are not consistent enough for this to work reliably at scale.
The solution is to define a Pydantic model or JSON schema that describes exactly what you need, then use a library like instructor to constrain the model output to that schema. The library handles retries and validation automatically, so you get structured data back or a clear error, not a garbled string you have to interpret.
Apply this pattern to every agent action that produces data consumed by another system. Tool call arguments, extracted entities, classification results, routing decisions: all of these benefit from schema enforcement.
The overhead is minimal. You write the schema once, and you gain confidence that downstream systems get well-formed inputs. That confidence compounds as your pipeline grows more complex.