Overview
Output parsers transform raw language model outputs into structured, typed data. They handle parsing, validation, and error recovery.StringOutputParser
Extracts string content from AI messages. Import:StructuredOutputParser
Parse output into a structured format using a Zod schema.JsonOutputParser
Parse JSON output from models.CommaSeparatedListOutputParser
Parse comma-separated values into an array.Output Fixing Parser
Automatically fix malformed output using another LLM call.Custom Output Parser
Create custom parsers for specific needs:Using with Structured Output
Modern chat models support native structured output, which is more reliable:Format Instructions
Most parsers provide format instructions to include in prompts:Error Handling
Parser Methods
Parse the output string into structured format
Get instructions to include in the prompt
Parse from a chat generation result
Best Practices
Use native structured output when possible
Use native structured output when possible
Modern models support
withStructuredOutput which is more reliable:Include format instructions in prompts
Include format instructions in prompts
Always include the parser’s format instructions:
Validate schemas with Zod
Validate schemas with Zod
Use Zod for runtime type safety:
Related
Chat Models
Using structured output with chat models
Prompts
Using parsers with prompts
