Phase 08 · LangChain & LangGraph agentic systems Core

Output parsers and structured responses

An Output Parser turns model text into the shape your app expects: plain strings, JSON Output, validated objects or Structured Output.

In plain terms

The model naturally writes prose. Your app often needs a clean object. A StrOutputParser gives plain text; a PydanticOutputParser validates fields with a Pydantic schema; provider-native Structured Output can force JSON Output directly.

Why it matters

Agentic apps pass model output into tools, databases and UI components. Loose text breaks those handoffs, so parsing and validation are production basics.

How it works

Use a StrOutputParser when the final answer is just text. Use PydanticOutputParser or schema-based Structured Output when the result feeds code. Validate, retry with the validation error, and keep schemas narrow.

When you use it

Extraction, classification, routing, tool arguments, evaluator judgments, citations and any response your code consumes.

Common mistakes

  • Regex-parsing chatty answers instead of asking for a schema.
  • Using a schema with vague field names.
  • Skipping validation and discovering broken JSON downstream.

Best practices

  • Prefer provider-native structured output when available.
  • Keep parser errors visible in traces.
  • Add examples for tricky optional fields.

Try it yourself

Parse a messy support email into a Pydantic object with priority, customer, issue_type and next_action.