Structured Outputs: JSON Schema vs Free Text

9 min read

268
Structured Outputs: JSON Schema vs Free Text

JSON Schema Vs Free Text

Structured outputs ask a model to return data in a machine-readable format, usually JSON, constrained by a schema. Free text asks for a natural-language response that may include lists, headings, or partial details, but it does not enforce a strict structure. In health-adjacent workflows, the difference shows up in parsing, validation, and how errors surface when something goes wrong.

For example, a symptom intake tool might need fields like onset_date, symptom_duration_days, severity_scale, and red_flags. With JSON Schema, the tool can reject responses that miss required fields or violate types. With free text, the same tool must guess where the onset date appears, which often breaks when the wording shifts, which, frankly, most people skip during testing.

JSON Schema also changes how you design prompts and downstream logic. You trade some flexibility for predictable structure, then you decide how strict to be about optional fields, enumerations, and formatting. A schema that is too strict can cause frequent failures, while one that is too loose can still produce unusable data.

Common Failure Modes

People often treat structured outputs as a guarantee of correctness, then they stop checking. A schema can validate shape without validating medical truth. If the model confidently fills onset_date with an incorrect date, JSON validation still passes because the value matches the expected type.

Another frequent issue comes from mismatched assumptions between the schema and the prompt. If the schema expects severity_scale to be an integer from 0 to 10, but the prompt asks for “mild, moderate, severe,” the model may return strings that fail validation. When teams loosen the schema to avoid failures, they may accept inconsistent representations like “7/10,” “seven,” or “moderate,” which complicates later steps.

Free text has its own failure modes. The model may omit key details, reorder facts, or include hedging language that breaks extraction rules. Even when the answer looks readable, automated systems that scan for patterns can miss the relevant part, especially when the model uses synonyms or changes phrasing.

Supporting technologies matter. JSON Schema validation depends on a parser and a validator library, and those tools have their own edge cases. Prompting frameworks also influence output formatting, such as whether the system wraps JSON in code fences or adds trailing commentary. I’ve seen this happen with toolchains around 2024-10 where the “JSON mode” setting was enabled, yet the model still appended a short explanation after the JSON.

Practical Advice For Choosing

Use JSON When You Need Fields

Choose JSON Schema when you need reliable extraction into specific fields, such as medication name, dosage, frequency, and start_date. A typical approach is to define required fields for the minimum viable record, then mark everything else optional. In many health-adjacent intake flows, requiring 6 to 10 fields reduces downstream ambiguity without forcing the model to invent missing details.

Set enumerations for fields with known categories, such as route values like “oral,” “topical,” or “intravenous.” Use numeric types for scales and durations, then add constraints like minimum and maximum. If you cannot guarantee the model will always know the unit, store both value and unit, or store a normalized unit plus a raw_text field for audit.

Keep Free Text For Human Review

Use free text when the output is primarily for human reading, such as drafting a patient-friendly explanation of what a lab result means. In those cases, you can accept variability in phrasing because the reader interprets meaning. Still, you can reduce risk by asking for a consistent structure in the text, such as “Symptoms,” “Timeline,” “Current meds,” and “Questions for the clinician,” even though the format is not machine-validated.

If you later need extraction, treat free text as a source document. Run a second pass that extracts structured fields, then validate the extracted JSON against a schema. This two-stage pattern often catches omissions earlier, though it adds latency and another failure point.

Validate Shape And Meaning

Validation should happen in layers. First, validate JSON against the schema so your parser never guesses. Second, add semantic checks that do not require medical judgment, such as date formats, duration consistency, and range checks. For example, if onset_date is present and symptom_duration_days is present, you can verify that duration is non-negative and not wildly inconsistent with the date difference.

Semantic checks catch formatting errors and some hallucination patterns, but they cannot confirm diagnosis. Keep a “confidence” field separate from validation results. A schema-valid response can still be wrong, so your UI should reflect that distinction.

Test With Adversarial Inputs

Test both formats with messy inputs: typos, missing dates, mixed units, and contradictory statements. A small test set of 50 to 200 anonymized examples often reveals whether the model reliably fills required fields or whether it drifts into narrative. Track two metrics: schema pass rate for JSON, and extraction completeness for free text.

When you see repeated failures, adjust the prompt and schema together. If the model frequently returns “unknown” for a required field, consider making that field optional and adding an explicit “unknown_reason” enum. That change reduces forced invention, which is a common reason structured outputs look confident while still being unreliable.

Educational Case Examples

Scenario A: Medication list extraction A clinic assistant tool asks for a structured medication record from a patient message. The schema requires medication_name, dose, unit, frequency, and route. In one anonymized test, the model returns route as “oral” and frequency as “twice daily,” which passes validation only after the schema allows a frequency string plus a normalized_frequency field. The team then adds a semantic rule: if route is “topical,” dose must not include “mg” unless the unit is explicitly allowed for that route.

Scenario B: Symptom timeline drafting A patient asks for a summary of symptoms to share with a clinician. The system returns free text with sections for onset, progression, and associated symptoms. A later extraction step attempts to pull onset_date and severity. In tests, free text sometimes uses relative phrases like “about a week ago,” so the extraction returns null for onset_date. The workflow handles this by asking the user a follow-up question only when onset_date is missing, rather than forcing a guess.

Comparison Checklist

Decision Point JSON Schema Free Text Practical Recommendation
Need machine parsing High, if schema matches requirements Low, extraction is heuristic Use JSON for fields that drive actions
Handling missing info Use optional fields and explicit unknown Model may omit details silently Ask follow-ups when required facts are absent
Validation scope Shape validation, not medical truth No schema checks Add semantic checks and human review for clinical use
Failure visibility Clear: parse errors or schema violations Hidden: plausible text with missing fields Track pass rate and extraction completeness metrics

Step-by-step checklist for decision support:

  1. List the fields your downstream system needs to act, such as dose, unit, and timing.
  2. Mark which fields are required versus optional, then define an explicit unknown representation.
  3. Run a small test set and measure JSON schema pass rate and extraction completeness for free text.
  4. Add semantic checks for dates, ranges, and unit consistency, then log failures for prompt or schema tuning.
  5. Route outputs to human review when they influence clinical decisions or patient safety.

Common Mistakes To Avoid

One mistake is treating schema validity as correctness. A response can pass validation while still contradicting the user’s message, especially when the prompt encourages confident completion. Your logs should separate “schema passed” from “facts matched the source text.”

Another mistake is designing a schema that mirrors the model’s preferred phrasing instead of the user’s reality. If the schema expects a single date field but users often describe timelines as “last month” or “two weeks after,” the model will either fail validation or invent a specific date. A better pattern stores raw timeline text and an optional normalized date.

Teams also over-tighten constraints. If you restrict severity to an integer 0 to 10, but the user provides “moderate,” the model may return null or fail. Loosen the schema with a severity_label enum and a severity_score optional field, then map labels to scores only when the label is present.

Finally, avoid mixing JSON and narrative in the same response without a strict rule. If the output sometimes includes commentary before or after JSON, parsers break. Many toolchains add a “JSON only” instruction, yet some wrappers still add extra text, so you should test the exact integration path, not just the model behavior in isolation.

FAQ

What does JSON Schema validate?

It validates the structure and types of the JSON output, such as required fields, allowed values, and numeric ranges. It does not validate medical accuracy or whether the content matches the user’s intent.

Why does free text break extraction?

Free text can change phrasing, reorder details, or omit fields without signaling that information is missing. Extraction systems then rely on heuristics that fail when wording shifts.

How strict should a schema be?

Use required fields for facts that drive downstream actions, and keep other fields optional with an explicit unknown representation. Tight constraints reduce ambiguity but increase failure rates when users provide incomplete information.

Can structured outputs still hallucinate?

Yes. The model can generate plausible values that satisfy the schema while being wrong. Validation checks shape, not truth, so you still need semantic checks and source-grounding practices.

What testing metrics should I track?

For JSON, track schema pass rate and the fraction of required fields that are non-null. For free text, track extraction completeness and the rate of null or low-confidence extracted fields.

Author's Insight

Structured outputs improve reliability when the goal is to move information into software systems that need predictable fields. JSON Schema helps you detect formatting and missing-field problems early, which reduces silent failures that often occur with free text. Validation still cannot confirm clinical correctness, so semantic checks and human review remain part of a safe workflow.

In practice, the best results come from treating the schema as a contract for data shape and from designing follow-up questions for missing facts. I’ve also found that integration testing matters as much as prompt design, because wrappers can add extra text around JSON even when “structured output” is requested.

Key Takeaways

  • JSON Schema enforces output structure, while free text leaves structure to interpretation.
  • Schema validation checks format, not medical truth, so add semantic checks and review steps.
  • Design schemas for real user input by using optional fields and explicit unknown values.
  • Measure outcomes with pass rate and extraction completeness, then tune prompt and schema together.
  • Test the full integration path, since some toolchains can alter formatting and break parsers.

Was this article helpful?

Your feedback helps us improve our editorial quality

Latest Articles

AI Tools 22.11.2026

RAG Chunking: 500 vs 1,000 Token Chunks

This article explains how Retrieval-Augmented Generation (RAG) splits documents into chunks and why chunk size changes answer quality. It is for readers evaluating RAG systems for research, support, or health-adjacent knowledge bases. You will learn what 500-token and 1,000-token chunks change in retrieval, context, and cost, plus practical ways to test chunking using real metrics. The guide also covers common failure modes and a decision checklist.

Read » 477
AI Tools 03.11.2026

AI Errors: Measuring Hallucination Rates

This article explains how to measure hallucination rates in AI systems that generate text, summaries, or answers. It’s for readers who want reliable evaluation beyond vague claims, including people reviewing AI outputs for health-adjacent information. You’ll learn how to define “hallucination,” choose test sets, score factuality with human and automated checks, and interpret results with uncertainty. Practical examples show how measurement choices change the numbers.

Read » 402
AI Tools 16.11.2026

MCP Servers: Tools, Resources and Prompts

MCP servers connect AI apps to external tools through a standard protocol. This guide explains what MCP servers do, which dependencies matter, and how to test prompts and tool calls without guessing. It is for developers and health-adjacent teams who want reliable tool access for research, documentation, and workflow automation. You will learn practical setup checks, prompt patterns, example scenarios, and a decision checklist to reduce errors and avoid unsafe tool use.

Read » 359
AI Tools 13.11.2026

API Data Retention: Training vs Storage

API data retention affects how long providers keep your requests, how they separate training from storage, and what rights you have when data is reused. This article explains retention terms in plain English for people evaluating health-adjacent apps, analytics, and AI features. You will learn how training differs from storage, which clauses to look for, what technical signals matter, and how to reduce risk when an API vendor keeps logs.

Read » 177
AI Tools 01.11.2026

AI Agents: Tool Calls per Task

AI agents can call tools (search, databases, code, calendars) while they work on a task. This article explains how “tool calls per task” affects cost, latency, reliability, and safety. It’s for readers evaluating agent demos, writing prompts, or setting internal rules for automated workflows. You’ll learn how to measure tool-call counts, what failure modes look like, and how to design tasks that finish with fewer calls without losing correctness.

Read » 243
AI Tools 25.11.2026

Structured Outputs: JSON Schema vs Free Text

This article explains how structured outputs work when an AI system must return data in JSON that follows a schema, compared with returning free-form text. It’s for readers evaluating AI tools for health-adjacent tasks like summarizing symptoms, extracting medication details, or drafting patient instructions. You’ll learn how JSON Schema changes reliability, where it still fails, how to test outputs, and what to watch for when accuracy matters.

Read » 268