keepcalculator

06 Numbers and Powers

Structured Outputs vs Function Calling in the OpenAI API

Card No. 06·36308 · Updated · Standard formula, shown below

Use structured outputs when you need the model’s reply to follow a defined data shape, such as a JSON object your application can parse. Use function calling when the model needs to request an action from your application or a connected tool; your code runs the function and can return its result to the model.

The key distinction

These features address different parts of an integration. Structured outputs constrain the form of the assistant’s response. Function calling gives the assistant a way to propose a tool invocation, such as looking up an order or running a calculation. A tool call is not the same as the model executing code: your application receives the request, decides what to do, and supplies the result.

The choice is about intent, not whether the data happens to be JSON. Tool calls are represented in a structured format too, but their purpose is to communicate an action request. A JSON answer can describe a proposed action without actually invoking a tool.

How structured outputs work

With structured outputs, you provide a schema describing the response you want. In supported API interfaces, this is commonly configured through a response format using JSON Schema, with strict adherence enabled where available. The model then produces a response intended to conform to that schema.

For example, a support application might ask for a classification object:

  • category: a value from an allowed set, such as “billing,” “technical,” or “other”
  • urgent: a Boolean
  • summary: a short string

This is useful when the application needs consistent fields rather than free-form prose. A schema can define types, required fields, and certain constraints. The exact supported JSON Schema features depend on the API and model, so check the current documentation rather than assuming every schema keyword is accepted.

Schema compliance does not guarantee that the content is true, complete, or appropriate. The model can produce a well-formed classification that is still wrong. Your application should handle refusals and incomplete or unexpected outcomes, and validate any values that matter beyond the schema’s guarantees.

How function calling works

For function calling, your application provides tool definitions: names, descriptions, and argument schemas. The model can respond with a request to call one of those tools and arguments that match the declared shape. Your application receives that request, validates it, runs the appropriate code if allowed, and sends the tool result back into the conversation when further model reasoning is needed.

For example, an assistant asked “Where is order 8472?” could request a tool named get_order_status with an order identifier. Your server would check the request, query its order system, and return the result. The model can then explain the status to the user. The tool definition alone does not connect to a database or authorize access.

A typical cycle is:

  1. Send the conversation and available tool definitions to the API.
  2. Inspect the response for a tool call, rather than treating every response as user-facing text.
  3. Check the tool name and arguments, apply authorization and business rules, and run the tool if permitted.
  4. Send the tool output back to the model if the interaction should continue, then present the final answer.

Depending on the API interface, tool selection can be left to the model, restricted to a particular tool, or disabled. Consult the relevant API documentation for the exact settings and response structure.

How to choose

Ask what your application needs the model to do next. If it needs a predictable data response, use structured outputs. If it needs the model to request an operation that your application performs, use function calling. These can also be combined: a model can call a tool to retrieve information and then produce a final answer in a required schema.

  • Choose structured outputs for extraction, classification, content metadata, form-like answers, or other results that need known fields.
  • Choose function calling for operations such as searching a catalogue, checking a record, retrieving current application data, or asking a service to perform an action.
  • Use both when the workflow needs an external operation and a machine-readable final result.
  • Use ordinary text when a human-readable answer is enough and neither strict structure nor a tool request is needed.

Consider a travel assistant. Returning a list of suggested destinations with fields for name and explanation is a structured-output task. Checking live availability through an application’s booking service is a tool task. Returning the checked options in a fixed object can involve both.

Common misconceptions and failure points

“JSON means function calling.” It does not. A JSON response can simply be data for your application. Function calling is specifically a request for your application to run a named tool.

“A tool call runs automatically.” It does not. The model proposes a call; the surrounding application controls execution. This separation lets the application enforce permissions, reject invalid requests, and avoid actions that the user did not authorize.

“A schema makes the answer correct.” It only constrains format and supported structural rules. It does not verify facts, guarantee that a field was inferred correctly, or replace domain checks. Treat model-generated values as untrusted input when they affect application behavior.

Also plan for outcomes that are not a normal completed answer. A model may refuse, request a tool, or produce an incomplete response because of an interruption or token limit. Your integration should inspect the response state and handle these cases instead of blindly parsing text as the expected object.

For tool calls, validate arguments on the server even if they match the declared schema. Check the user’s authorization, restrict which records or operations are accessible, and require confirmation for consequential actions where appropriate. Avoid exposing secrets in tool definitions or relying on the model to enforce access controls.

Testing and implementation choices

Start with the smallest schema or tool set that supports the task. Clear field names and descriptions help the model choose and fill the intended structure. Keep tool descriptions specific about when a tool applies and what its arguments mean; overlapping tools can make selection less reliable.

Test more than a successful example. Include missing information, ambiguous requests, invalid identifiers, tool failures, refusals, and cases where the model should not call a tool. Confirm that your code handles malformed or unexpected arguments and that it does not execute a call merely because one appeared in a response.

Structured outputs are often simpler when the application only needs data, because there is no tool-execution loop. Function calling adds the useful ability to obtain external results or initiate operations, but also requires orchestration, validation, and error handling. Neither choice is inherently more accurate; accuracy depends on the task, instructions, available data, and checks in your system.

Frequently Asked Questions

Can I use structured outputs and function calling together?
Yes. A workflow can use a tool call to obtain information, then ask for a final response that follows a schema. The exact request configuration depends on the API interface you use.

Does function calling let the model run my function?
No. The model returns a tool-call request. Your application must receive it, decide whether it is allowed, run the code, and optionally send the result back to the model.

Should I use function calling just to get JSON?
Usually not. If you only need data in a defined shape, use structured outputs. Use function calling when the model needs to ask your application to perform an operation.

Does structured output guarantee valid or truthful information?
It can enforce supported formatting and schema constraints, but it does not establish that the values are factually correct. Validate important content separately.

When should a tool call require user confirmation?
Consider confirmation for actions with meaningful consequences, such as sending a message or changing a record. The application should make that decision based on its permissions and risk rules, not leave it solely to the model.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →