๐Ÿ“… April 14, 2026โฑ 7 min readโœ๏ธ MoltBot Engineering
Structured OutputsData Extraction

Structured Outputs from LLMs: JSON Mode, Function Calling & Schema Enforcement

Getting free-form text from an LLM is easy. Getting reliable, typed, validated structured data is harder. Here's the three-layer approach that makes LLM outputs as dependable as a database query.

Most production AI workflows need structured data โ€” not prose. You want an invoice parsed into fields, a sentiment classified as positive/neutral/negative, or an entity extracted as a typed object. Each approach has different reliability tradeoffs.

Three approaches compared

MethodReliabilityFlexibilitySupported by
Prompt ("output JSON")~70โ€“85%Any schemaAll models
JSON Mode~95%Valid JSON, no schemaGPT-4o, Gemini
Structured Output / Function Calling~99.9%Any schemaGPT-4o, Claude, Gemini

Structured outputs with Pydantic (recommended)

from pydantic import BaseModel from moltbot import Client class Invoice(BaseModel): vendor_name: str invoice_number: str total_amount: float line_items: list[dict] due_date: str | None client = Client() # Schema enforced at API level โ€” no hallucinated fields invoice = client.extract( model="gpt-4o", schema=Invoice, content=pdf_text, prompt="Extract all invoice fields." ) print(invoice.total_amount) # always a float, never a string

Handling failures gracefully

When to use each method

Schema-enforced extraction on MoltBot

Pydantic enforcement, auto-retry on validation failure, confidence scoring. 14-day free trial.

Start Free Trial โ†’