# Structured output parsing skips stray braces and quotes in prose

> Agno now finds the JSON object in model output even when the prose before it has an unmatched } or ", and output_schema parsing returns the object.

- Published: 2026-09-23
- Author: Akadiri Oluwagbemi Enoch
- Categories: Changelog
- Canonical: https://www.agno.com/articles/structured-output-parsing-skips-stray-braces-and-quotes-in-prose
- Markdown: https://www.agno.com/articles/structured-output-parsing-skips-stray-braces-and-quotes-in-prose.md

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):

```text
'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](https://docs.agno.com/input-output/structured-output/agent#json-mode) in the documentation.
