ModelRefs / Output Parser — AI Glossary

Output Parser — AI Glossary

A component that extracts structured data from raw LLM text output — handling JSON, markdown, lists, or custom formats.

Overview

Output parsers are the last mile of many LLM pipelines: they validate format, retry on parse failure, and transform strings into typed objects. LangChain, Instructor, and Marvin all provide output parsers with retry logic.

Reference details

Topicagents
Last reviewed2026-06-24

How it works

  1. A target shape is declared as a schema or type, so validity is a machine-checkable property rather than a judgement.
  2. The schema is also described to the model, usually in the prompt, since a parser cannot fix output that never aimed at the format.
  3. Raw output is validated against the schema, and failures carry a specific message about what did not conform.
  4. On failure the message is returned to the model so it can correct the output — a repair loop rather than a discard.
  5. Where the serving stack supports constrained decoding, the sampler is restricted to tokens the schema permits, which makes invalid output unreachable rather than merely retried.

Example: Repair versus constraint, in retries

At a 10% invalid rate with one repair attempt, roughly 1% of requests still fail after both, and the repair costs an extra call on 10% of traffic — so about 1.1 calls per request on average. Constrained decoding makes invalid output structurally impossible, so the rate is zero and there are no repair calls. The repair loop is the right answer when the provider offers no grammar support, and it is strictly worse when it does.

Commonly confused with

Sometimes equated with validation, which is one of its three jobs. It describes the format to the model, validates what comes back, and repairs failures by feeding the error back — and the last is what distinguishes a parser from a schema check. It is also not the same as constrained decoding: a parser works after generation and can only react, while constrained decoding restricts the sampler during generation so invalid output cannot be produced. Where both are available, the parser becomes a safety net rather than the mechanism.

When to use it

Reach for it when:

  • Downstream code needs typed data and the provider offers no constrained decoding.
  • Parse failures should be repaired by the model rather than surfaced as errors.
  • A schema can be stated precisely enough to validate against.

Reach for something else when:

  • Constrained decoding is available, which prevents the failure instead of repairing it.
  • Output is prose for a human, where imposing a schema adds nothing.
  • The schema is not described to the model, which makes repair the only mechanism and raises the failure rate.

Continue your research

Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to Output Parser — AI Glossary.

Frequently asked questions

What is Output Parser?

A component that extracts structured data from raw LLM text output — handling JSON, markdown, lists, or custom formats.

What concepts are related to Output Parser?

Closely related concepts include json mode, function calling.