Output Parsing
The process of extracting structured data from an AI model's free-text output—converting natural language into JSON, database records, API calls, or other machine-readable formats. Reliable output parsing is essential for AI agents because downstream tools and integrations require structured inputs. Techniques include JSON mode (constraining model output to valid JSON), function calling (the model emits structured function invocations), regex extraction, and grammar-constrained decoding. Parsing failures are a common source of agent errors in production.
Example
An agent analyzes an invoice and needs to extract vendor name, amount, date, and line items into a structured JSON object. Output parsing ensures the model's response is valid JSON with the expected schema—not a conversational summary with the data buried in prose.
Frequently asked questions
- What's the difference between output parsing and structured output?
- Structured output is a model capability where the output is guaranteed to conform to a schema (e.g., OpenAI's JSON mode, Anthropic's tool use). Output parsing is the broader practice of extracting structure from model outputs, which may include post-processing, validation, retries on malformed output, and fallback strategies. Structured output eliminates much of the need for manual parsing, but parsing logic is still needed for validation, error handling, and models that don't support structured output natively.