Structured output parsing skips stray braces and quotes in prose
September 23, 20261 min read
When a model answers an Agno output_schema request with text around the JSON, parse_response_model_str and parse_response_dict_str fall back to an extractor that scans the text for {...} spans. That extractor tracked braces and quotes across the whole text, prose included.
A lone } in the prose pushed the brace depth below zero, so the object's own { never counted as a start. A lone " opened a string the scanner never closed, and every character after it, braces included, read as string content. Both returned nothing, Agno logged All parsing attempts failed, and the parse returned None.
The extractor now skips a closing brace that has no open object. It scans the text twice, once reading a quote in prose as the start of a string and once ignoring it, and keeps the spans that decode as JSON. _extract_json_objects and parse_response_dict_str return these results for three model replies (real output):
'You close the object with } like so: {"theme": "dark"}'
Before: [] None
Now: ['{"theme": "dark"}'] {'theme': 'dark'}
'The user asked "what is the config: {"theme": "dark"}'
Before: [] None
Now: ['{"theme": "dark"}'] {'theme': 'dark'}
'Here is the result: {"theme": "dark"}'
Before: ['{"theme": "dark"}'] {'theme': 'dark'}
Now: ['{"theme": "dark"}'] {'theme': 'dark'}parse_response_model_str with a Pydantic model returned None before and theme='dark' now for the first two replies.
Learn more about structured output and JSON mode in the documentation.
Frequently asked questions
When the text before the JSON object held an unmatched } or ", the Agno JSON extractor lost track of where the object started and found nothing. Agno now skips those characters in prose and returns the object.
Agno extracts JSON objects when an agent or team has an output_schema and the model returns text that is not directly parseable. parse_response_model_str and parse_response_dict_str fall back to the extractor in that case.





