Home / Blog / Generative AI & RAG

    Structured Outputs and Function Calling: Making LLMs Reliable in Production

    By Softworth Solutions · · 4 min read · For readers in UK, US, India

    Hands typing on a keyboard at a clean desk

    In short: Structured outputs make an LLM return data that matches a JSON schema you define, and function calling lets it ask your code to run a named function with typed arguments. Together with validation and retries, they remove most of the parsing errors that make LLM features feel unreliable, but they guarantee shape, not truth.

    Early LLM integrations asked the model to reply in JSON and hoped for the best. Sometimes it wrapped the JSON in chatty commentary, added a trailing comma or renamed a field. Each of those is a production incident when downstream code expects a fixed structure, and they always seem to happen on the inputs you didn't test.

    What are structured outputs and function calling?

    Structured outputs constrain the model's final answer to a schema, written in JSON Schema, so your code can parse it without fragile string handling. Function calling, also called tool calling, gives the model a list of tools with names, descriptions and argument schemas. The model decides whether to call one, your code runs it, and the result goes back to the model.

    Three ways to get structured data from an LLM
    ApproachHow it worksReliability
    Prompt onlyAsk for JSON in the instructionsFails occasionally, often on edge cases
    Structured outputsProvider constrains output to your schemaShape guaranteed within supported schema features
    Function callingModel returns a tool name and typed argumentsShape guaranteed; choice of tool still needs testing

    In code, define each schema once as a typed model, such as Pydantic in Python or Zod in TypeScript, generate the JSON Schema from it and parse responses back into that type. Supported schema features vary by provider, so check the docs.

    How do you design schemas and tools the model gets right?

    • Use descriptive field names and short descriptions; the model reads them.
    • Prefer enums to free text for categories and statuses.
    • Make missing information nullable, and tell the model to use null rather than guess.
    • Give each tool one clear job: get_order_status beats a general run_query tool.
    • Check permissions inside every tool for the real user, never trusting the model's arguments.
    • Require human confirmation for actions that spend money or send messages externally.

    Standards like the Model Context Protocol make tools reusable across apps, but the design rules stay the same. Our post on designing tool-using agents covers agent patterns in more depth.

    An illustrative example

    Picture a UK insurance broker extracting claim details from customer emails. The output always parses, but a weekly review finds claim amounts that don't match the attached invoice. The schema was fine; the content wasn't. The team adds business checks after parsing: amounts must match invoice totals, policy numbers must exist in the database, and dates must fall inside the policy period. Failures retry once with the error included, then go to a claims handler. Wrong amounts stop reaching the claims system.

    Why isn't valid JSON enough?

    Because a perfectly shaped response can still be wrong. An invoice total can be a valid number that doesn't equal the sum of line items. A customer ID can be correctly formatted and belong to someone else. Add a second layer of validation after parsing: cross-field checks, database lookups, range checks and permission checks.

    Then plan for failure explicitly. Allow one or two retries with the specific error fed back. Use idempotency keys so a retried tool call doesn't create duplicate orders. Keep a deterministic fallback, such as a standard form or human handoff, for when the model can't finish the job.

    Hands typing on a keyboard at a clean desk

    Key facts

    • JSON Schema is an open specification for describing the structure of JSON data, and it is the format most LLM providers use for tool and output schemas. (JSON Schema)
    • OpenAI introduced Structured Outputs in its API in 2024, allowing developers to require responses that conform to a supplied JSON Schema. (OpenAI)
    • The Model Context Protocol, introduced by Anthropic in 2024, is an open standard for connecting AI applications to tools and data sources. (Model Context Protocol)

    How should you test structured LLM features?

    Measure field-level accuracy on real inputs, not just whether the JSON parses. For tools, check the right tool is chosen with the right arguments, and that the model doesn't call tools when it shouldn't. Include awkward cases: missing data, conflicting information, other languages and prompt-injection attempts. Run the suite in CI on every prompt, schema or model change. UK and US enterprise buyers increasingly ask to see this kind of evidence during vendor reviews, so keep the results.

    Key takeaways

    • Use provider structured outputs instead of prompt-only JSON.
    • Design narrow tools and enforce permissions inside them.
    • Validate content with business rules after parsing.
    • Test tool choice and field accuracy in CI.

    Softworth Solutions (SWS AI) in Coimbatore, India builds production LLM features for clients in India, the UK and the US. If your feature works in demos but breaks in production, we're happy to review your schemas and tools.

    Frequently asked questions

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

    Structured outputs constrain the model's final answer to your schema. Function calling lets the model request that your code run a named function with typed arguments, then continue with the result.

    Do structured outputs stop hallucinations?

    No. They guarantee format, not accuracy. You still need grounding in source data, business validation and human review for high-stakes outputs.

    Can open-source models do function calling?

    Many recent open-weight models are trained for tool calling, and inference servers support constrained decoding. Reliability varies more than with frontier hosted models, so test on your own tools.


    Planning an AI or software project? Talk to our team for a free consultation and an honest estimate.

    Previous: AI for Retail Stores: Inventory, Footfall and Pricing
    Next: Change Management for AI Adoption: Getting Your Team On Board

    Keep reading