structured-output-repair · EN · 2026-10-25

Structured Output via JSON Mode vs. Function Calling vs. Prompt-Only on One Key: Which Actually Holds Shape

Compare three structured-output mechanisms—JSON mode, function calling, and prompt-only—across different model backends via a single API aggregator. Learn how each behaves, where they break, and a fallback ladder to keep output shape reliable.

Structured output is essential for integrating LLM responses into code. But not all models support the same mechanisms. This guide compares JSON mode, function calling, and prompt-only approaches as they behave through a multi-model aggregator, and provides a fallback ladder to maintain shape when a preferred mode is unavailable.

How structured output works across backends

When you call different models through an aggregator, you are interacting with heterogeneous backends. Each backend has its own implementation of structured output, and support varies:

  • JSON mode: The model is instructed to return valid JSON, often with a schema or format hint. Some models enforce strict JSON; others best-effort it.
  • Function calling: The model emits a structured call (name + arguments) that you can parse. Support and parameter schemas differ per provider.
  • Prompt-only: You describe the desired format in the prompt and hope the model complies. No enforcement.

The aggregator normalizes these differences at the API level, but the underlying model capabilities still determine how reliably each mode holds shape.

JSON mode: strict schema vs. best-effort

JSON mode is the most direct way to get structured output. However, its reliability depends on the backend:

  • Strict JSON backends guarantee valid JSON and may enforce a schema (e.g., required fields, types). If the schema is supported, output shape is reliable.
  • Best-effort backends return JSON-like text but may include markdown fences, trailing commas, or missing fields. You must validate and possibly retry.

Through the aggregator, JSON mode requests are passed to the model as-is. Check the model's documentation for schema support. If the model does not support JSON mode, the request may be ignored or return an error.

Function calling: provider-specific reliability

Function calling lets you define a function with parameters, and the model returns a structured call object. Reliability varies:

  • Models trained for function calling (e.g., GPT-4, Claude) generally produce well-formed arguments, but may hallucinate function names or omit optional fields.
  • Smaller or open models may not support function calling at all, or may produce malformed arguments.

In the aggregator, function calling is exposed uniformly, but the backend's implementation determines fidelity. Always validate the returned arguments against your schema.

Prompt-only: flexible but fragile

Prompt-only structured output relies entirely on the model following instructions. It works across all models but is the least reliable:

  • Output may include extra text, markdown, or explanations.
  • Parsing requires robust extraction (e.g., regex for JSON blocks).
  • Reliability drops with smaller models or complex schemas.

Use prompt-only as a last resort or when you need maximum model compatibility and can tolerate parsing effort.

Fallback ladder for unsupported modes

Not every model supports every mode. When your preferred mode is unavailable, follow this ladder to maintain output shape:

  1. Try JSON mode with schema if the model supports it. If you get a schema validation error, move to step 2.
  2. Try function calling with a single function whose parameters match your schema. If the model does not support function calling or returns malformed arguments, move to step 3.
  3. Fall back to prompt-only with explicit format instructions and few-shot examples. Always validate and retry on parse failures.

Implement this ladder programmatically: detect mode support (via model metadata or error handling) and degrade gracefully.

Validation and retry strategies

Regardless of mode, always validate structured output before use. Common patterns:

  • Use JSON Schema validation for JSON mode and function arguments.
  • For prompt-only, extract JSON via regex and validate.
  • On failure, retry with a stricter prompt or switch to a more reliable mode (e.g., from prompt-only to JSON mode if the model supports it).
  • Limit retries to avoid infinite loops.

Practical tips for aggregator users

  • Check model capabilities before choosing a mode. The aggregator's model list may indicate supported features.
  • Normalize output across backends: strip markdown fences, fix trailing commas, and coerce types when safe.
  • Log mode and model with each request to diagnose shape failures.
  • Use the fallback ladder to abstract over backend differences and keep your application resilient.

By understanding how each structured-output mechanism behaves per backend and implementing a fallback ladder, you can maintain reliable output shape even when models vary.