Skip to content
LLM engineering · Reliable output · Pattern selection

Function Calling vs. Structured Output: Which One for Production LLM Apps?

Both approaches force reliable LLM output. They solve different problems. Function calling = model decides whether to invoke a tool. Structured output = model must conform to a schema. Most teams use the wrong one for their workload — here's the decision matrix.

By Andy Gaber, Founder, Digital Dashboard HubUpdated

Anthropic and OpenAI both support two distinct mechanisms for getting reliable structured output from LLMs: function calling (also called 'tool use') and structured output (also called 'JSON mode' or 'structured outputs' depending on vendor). The two are often conflated in casual discussion but solve overlapping-yet-distinct problems with different cost, latency, and quality profiles. Picking the wrong one produces unnecessary complexity or unreliable output.

Below: the mechanics of each, the workload signatures that pick one over the other, cost and latency math, six worked production scenarios, and the patterns that combine them. Sources include Anthropic's tool use documentation, OpenAI's structured outputs guide, OpenAI's function calling documentation, Google's Gemini structured output documentation, LangChain's tool calling concepts at python.langchain.com, the Instructor library by jxnl on GitHub (structured output library for Python), Pydantic AI documentation at ai.pydantic.dev, and the Willard & Louf 2023 'Efficient Guided Generation for Large Language Models' arXiv:2307.09702 paper on the underlying JSON-schema-constrained decoding research.

Function calling vs. structured output — head-to-head

Feature
Function calling
Structured output
Model decides whether to invoke
Output guaranteed to match schemaTool call structure yes; arguments validated by youYes — sampling constrained
Per-query cost (relative)1-3×
Latency2-8 seconds1-5 seconds
Iteration / multi-stepNative via tool result loopSingle call (combine with chain-of-prompts for multi-step)
Best forChat that uses tools, agents, researchExtraction, classification, transformation
Common mistakeUsed for pure extraction (overkill)Used for chat that needs decision-making (loses intelligence)

Mechanics from [Anthropic tool use](https://docs.anthropic.com/en/docs/build-with-claude/tool-use), [OpenAI structured outputs](https://platform.openai.com/docs/guides/structured-outputs), [OpenAI function calling](https://platform.openai.com/docs/guides/function-calling), and [Google Gemini structured output](https://ai.google.dev/gemini-api/docs/structured-output). Cost ratios are per-query relative; for high-volume workloads the 2-3× difference is meaningful.

Function calling — the mechanic

**What it does:** You define one or more 'tools' (functions) the model can invoke. Each tool has a name, description, and parameter schema. The model decides whether to call a tool, which tool to call, and what parameters to pass. The actual function execution happens in your code; the model gets the result back in the next turn.

**Mechanism:** Model receives the tool definitions in the system prompt context. When the model wants to invoke a tool, it returns a structured tool-call object instead of plain text. Your code parses the tool call, executes the function, and feeds the result back to the model as a tool-result message.

**Best for:** Tasks where the model needs to interact with external systems (API calls, database queries, calculations) AND the model should decide whether/when to interact. The decision-making is part of the value.

**Documentation:** Anthropic tool use, OpenAI function calling.


Structured output — the mechanic

**What it does:** You define a JSON schema (or equivalent structured spec). The model is forced to produce output that conforms to the schema. No decision-making about whether to produce output — the output IS the response.

**Mechanism:** The model's token sampling is constrained to only produce tokens that maintain schema-compliance. The output is guaranteed valid against the schema at the API level.

**Best for:** Tasks where you need reliable extraction or transformation INTO a specific shape — pulling fields from a document, converting natural language to a structured command, generating data records. The model isn't deciding whether to extract; you've already decided.

**Documentation:** OpenAI structured outputs, Google Gemini structured output. Anthropic supports structured output via tool use with a 'forced tool choice' parameter — slightly different mechanic, same outcome.


The 6 production scenarios — which to pick

**Scenario 1 — Customer-support chatbot that sometimes needs to look up account info.** Model decides whether to call the lookup. **Function calling.** Forcing structured output here would require always returning the lookup, even when not needed.

**Scenario 2 — Extracting 12 fields from invoice PDFs.** Output shape is fixed (the 12 fields). Model isn't deciding; you're requiring extraction. **Structured output.** Forcing function calling here adds the unnecessary 'should I call this' overhead.

**Scenario 3 — Agent that does research across multiple tools.** Model decides which tools to call, in what order. **Function calling.** Multiple iterations possible.

**Scenario 4 — Classifying support tickets into 12 categories with confidence scores.** Output shape is fixed (category + confidence). Model isn't deciding whether to classify. **Structured output.**

**Scenario 5 — Natural-language-to-SQL converter.** Output shape is the SQL string (or structured query AST). **Structured output** — JSON schema for the query shape works well.

**Scenario 6 — Chat interface that should answer most questions conversationally but sometimes invoke a calculator or web search.** Mixed mode: model needs to decide. **Function calling.** Conversational answers come back as plain text; tool invocations come back as structured tool calls.


Cost and latency comparison

**Function calling per-query cost:** 1-3 model calls typically (initial + tool result + final response). Tool definitions add ~500-2000 tokens to system prompt context per call. Latency: 2-8 seconds depending on tool invocations.

**Structured output per-query cost:** 1 model call. No additional system prompt overhead. Latency: similar to plain-text generation (1-5 seconds).

**Reliability:** Both are highly reliable when used in their right context. Structured output guarantees schema compliance at the API level (the model literally cannot return invalid JSON). Function calling produces tool calls reliably but you still validate the tool arguments yourself.

**The cost difference:** Structured output is 2-3× cheaper per task than function calling for tasks where both could work. Function calling pays for the additional intelligence (the model's decision about whether to invoke); structured output doesn't have that intelligence but also doesn't pay for it.


When to combine both

Many production workflows benefit from combining. Common patterns:

**Function calling for tool selection + structured output for tool argument generation.** Model decides which tool to call (function calling), then a sub-call with structured output generates the exact arguments. Reduces tool-argument errors at modest cost premium.

**Routing via structured output + function calling in handlers.** Initial router call uses structured output to classify the request into a handler category; handler call uses function calling for the multi-tool interactions within the category.

**Final-answer structured output after a function-calling research phase.** ReAct-style research using function calling, then a structured-output final-answer pass that formats the result into a guaranteed-schema response. Common in agentic systems that need to return parseable results.

These combinations cost more than either pattern alone but produce more reliable end-to-end results for complex workflows. Per Anthropic's agent design guide, the highest-quality production agents typically combine multiple mechanisms rather than using one purely.

Picking either pattern by default: uses function calling for everything (paying for unneeded decision-making) or structured output for everything (forcing model to always return data when it should sometimes refuse).
Picking by workload signature: structured output when output shape is fixed and required; function calling when model decides whether/how to invoke; both combined for complex workflows. 2-3× cost difference per query on the simple cases; meaningful reliability difference on the complex ones.

Pick the right mechanism per workload (4 steps)

  1. 1

    Ask: does the model need to decide whether to take an action?

    If yes (chat that sometimes calls tools, agent that picks among options) — function calling. If no (extraction, classification, transformation where the action is always 'produce this shape') — structured output. This single question correctly picks the right mechanism for ~80% of workloads.

    → Open the Code Prompt Builder
  2. 2

    Define the schema (for structured output) or tool signatures (for function calling)

    Structured output: JSON schema with the exact fields, types, and constraints. Function calling: tool name + description + parameter schema per tool. Per OpenAI's structured outputs docs, schema descriptions matter — the model uses them to understand intent.

  3. 3

    Test reliability on 100 representative inputs

    For structured output: 100% schema compliance is guaranteed at API level, but content quality varies — measure that. For function calling: model tool-selection accuracy. Both should hit 95%+ on representative inputs before production deployment.

  4. 4

    Add validators for the model's judgment calls

    Structured output guarantees shape but not content correctness. Function calling guarantees tool-call structure but not tool selection correctness. Downstream validators (does the extracted field make sense? is the chosen tool reasonable for the query?) catch the cases where the model is structurally compliant but semantically wrong.

Where to apply each mechanism in your system

If you're building a chatbot or agent: Function calling for any tool interactions. The decision-making intelligence is what justifies the cost premium. Pair with structured output for any final-format requirements after the function-calling work completes.

If you're extracting fields from documents: Structured output — schema-constrained sampling guarantees the output matches your data model. Don't use function calling for pure extraction; it's overkill and 2-3× more expensive.

If your workflow has multiple stages: Combine. Common pattern: function calling for tool-using research phase, structured output for final-format answer. The combination produces more reliable end-to-end results than either alone.

If you want to model the cost-quality tradeoff: Use the Code Prompt Builder to structure your workload definition. The mechanism choice should fall out of the workload, not the other way around.

Frequently Asked Questions

What's the difference between function calling and structured output?

Function calling lets the model decide whether to invoke a tool. Structured output forces the model to produce output matching a schema. Both produce reliable structured data but at different points in the workflow: function calling is for actions the model chooses to take; structured output is for outputs you require the model to produce in a specific shape. Per Anthropic's tool use docs and OpenAI's structured outputs guide, the mechanisms solve overlapping-yet-distinct problems.

When should I use structured output instead of function calling?

When you don't need the model to decide whether to take an action — you're always extracting, classifying, or transforming into a fixed shape. Examples: pulling 12 fields from invoices, classifying support tickets into 12 categories, converting natural language to SQL. Function calling here adds unnecessary decision-making overhead. Structured output is 2-3× cheaper per query and equally reliable for these workloads. See OpenAI structured outputs for the constrained-sampling mechanism.

Can I combine both in one workflow?

Yes, and many production workflows benefit from it. Common patterns: (1) function calling for tool-selection + structured output for tool-argument generation, (2) routing via structured output + function calling in handlers, (3) final-answer structured output after a function-calling research phase. Per Anthropic's agent design guide, the highest-quality production agents typically combine multiple mechanisms rather than using one purely.

Is structured output less reliable than function calling?

No — structured output is more reliable at the schema-compliance level because the API constrains token sampling to maintain schema validity. The output is guaranteed to be parseable JSON matching your schema. Function calling guarantees the structure of tool calls but not the validity of arguments; you validate those yourself. The 'reliability' comparison isn't apples-to-apples — they guarantee different things. For pure output shape, structured output is stronger. For workflow intelligence, function calling is stronger.

Which is faster?

Structured output. It's a single model call (typically 1-5 seconds) versus function calling's 1-3 calls (2-8 seconds for the full loop). For high-volume workloads where latency matters, structured output's lower per-query latency adds up. For workloads where intelligence matters more than speed, function calling's extra latency is the cost of the decision-making.

Pick the right reliable-output mechanism for each workload.

The Code Prompt Builder structures the workload analysis that determines mechanism choice. Free, no signup. Part of 40+ free prompt tools.

Browse all prompt tools →