VITALIFY.ASIA logo

Generative AI Is 90% JSON: Writing Schemas and Descriptions That Remove the Extra Line

Ask AI to "just return X" and it still adds "Anything else?" at the end. When a program consumes AI output, defining the shape with JSON Schema works far better than polishing the prompt. Here is how to write schemas and use description as a per-field prompt, with an inquiry-classification example.

Nihei TomotakaNihei Tomotaka
Generative AI Is 90% JSON: Writing Schemas and Descriptions That Remove the Extra Line
On this page

"Classify the following inquiry and return only the category name."

Here is the kind of answer you get back:

The classification is "Billing & Payment."

The customer is asking about the amount on their invoice, so I judged it to be billing-related. If you have any other questions, please feel free to ask.

For a human reader, that is a helpful answer. But what if you want a program to receive it and route each category to the right person? All you wanted was "Billing & Payment." Everything before and after it gets in the way.

Add "Don't write anything extra" or "Category name only" to the prompt, and it works for a while. Then, once in a hundred times, just when you have forgotten about it, "Is there anything else I can help with?" comes back.

If a program is going to use the AI's output, stop asking in the prompt and decide the shape of the output (the schema) instead. Books titled "X Is 90% of It" were a trend for a while. For building generative AI into systems, I think 90% of it is JSON—more precisely, the schema that defines the JSON's shape.

Key points

  • "Just return X" is only a request, and the AI adds a friendly line out of helpfulness. Defining the output shape with JSON Schema is far more reliable.
  • A schema's description is a prompt written per field. Putting each instruction next to its value is more stable than packing everything into one long prompt.
  • A schema guarantees only the shape, not whether the content is correct. You still need value checks and an escape route for when the AI is unsure.

Why the AI adds that extra line

Today's conversational AI is tuned to talk with people and be helpful. It explains its reasoning and closes by suggesting a next step. That is considerate behavior toward a person, and for the AI it is the "normal" way to answer.

"Category name only" is a request that goes against that normal. Because it is a request, it is usually followed, but not every time. With long input, ambiguous content, or a conversation that has gone on for a while, the usual habit shows up again.

From the system's side, a promise kept 99 times out of 100 is no different from a promise that is not kept. A single "anything else?" stops the processing that follows.

What changes when you define a schema

The major AI APIs now let you make the output follow a JSON Schema. OpenAI offers this as Structured Outputs; Anthropic offers it as Structured outputs and as input definitions for tool use.

For the inquiry classification above, you would pass a schema like this:

{
  "type": "object",
  "properties": {
    "reason": {
      "type": "string",
      "description": "Basis for the classification. Quote words from the inquiry, within 50 characters."
    },
    "category": {
      "type": "string",
      "enum": ["Billing & Payment", "Contract & Cancellation", "Bug", "How to use", "Other"],
      "description": "The main purpose of the inquiry. If several apply, pick the one the customer wants solved first."
    },
    "needs_human": {
      "type": "boolean",
      "description": "true if there is anger, a hint of cancellation, or a legal reference. When in doubt, true."
    }
  },
  "required": ["reason", "category", "needs_human"],
  "additionalProperties": false
}

What comes back is JSON in exactly this shape and nothing else:

{"reason": "Says the invoice amount differs from last month", "category": "Billing & Payment", "needs_human": false}

There is simply no place to write "anything else?" category can only hold one of five values, so wording drift ("billing-related", "about payment") cannot happen. In the article announcing Structured Outputs, OpenAI reported that on its evaluation of following complex JSON schemas, the model with strict mode scored 100%, while an earlier model without it (gpt-4-0613) scored under 40% (OpenAI, "Introducing Structured Outputs in the API", August 2024). According to the same article, a model only trained to follow schemas reached 93%; it took a mechanism that constrains token selection itself to the schema (constrained decoding) to reach 100%. In other words, "telling it firmly" does not close the last few percent.

Comparison: asking in free text mixes in extra lines and wording drift, while defining a schema returns only JSON in a fixed shape

Another big benefit: you set out to remove one extra line, and you also pin down the granularity of the information you want. With free text, whether the AI gives its reasoning, or flags the inquiry for a person, was up to the AI. Put them in the schema as fields, and they come back filled in every time.

A description is a "prompt per field"

The part of a schema that matters most is description. It looks like a mere comment field, but the AI reads it to decide the value. In other words, it is a prompt written per field.

If you line everything up in the prompt body ("decide the category by purpose, pick the first one if several apply, keep the reason within 50 characters, send angry customers to a person..."), the instructions drift apart and get mixed up. Split them into descriptions, and at the moment each value is decided, only that value's instruction sits next to it.

Keep these in mind when writing:

What to writeBad exampleGood example
What goes in"description": "category""description": "The main purpose of the inquiry"
How to decide when unsure(not written)"If several apply, pick the one the customer wants solved first"
Format and length"briefly""within 50 characters", "YYYY-MM-DD", "yen incl. tax, digits only"
When it is unknown(not written)"null if not stated in the text"

The one most often missed is the last: what to do when the answer is unknown. Without it, the AI makes up a plausible value just to fill the shape. Make the type ["string", "null"] and write "null if not stated" in the description, and you get null instead of fiction.

Tips for writing schemas

Use enum wherever the choices are fixed

For values with a fixed set of candidates, such as category, status, or priority, list them with enum. Downstream code can then simply say if (category === "Billing & Payment"), with no code to absorb wording drift. Include one "Other" for cases that fit none of them.

Put the reasoning before the answer

The AI writes JSON from top to bottom. Placing reason before category, as in the example above, makes it write the basis first and then decide, which tends to stabilize the judgment. The reason field also helps when a person checks the results later.

Don't nest too deep or pack too much

Ask one call to fill a schema with dozens of fields and many levels of nesting, and the quality of the later fields drops. Tasks with different goals, such as "classification" and "drafting a reply," end up more stable as separate calls.

Manage the schema alongside your code

A schema is a contract between the AI and the processing that follows. Write it as a type with Zod in TypeScript or Pydantic in Python and generate the JSON Schema from it, and it will never disagree with the receiving side's types. It is also easier to review than prompt wording.

What happens without a schema

Conversely, if you take free-text output without a schema, you get things like these:

  • Extra lines: More and more regex code to cut away the text around "It's X. Anything else?"
  • Shape drift: You ask for JSON and get it wrapped in code fences, keys that waver between category and Category, or output cut off midway.
  • Wording drift: The same category comes back as "Billing," "Billing-related," "About payment"—different every time.
  • Silent omissions: Information you asked for, such as the reason or a date, sometimes just doesn't come back, depending on the input.
  • Filled with fiction: With no rule for the unknown case, a plausible value goes in.

Each is a small problem on its own. But in a system processing thousands of items a day, the code to absorb this drift and the time spent investigating jobs that stopped because of it slowly pile up.

What a schema does not guarantee

Keep in mind that a schema guarantees only the shape.

It guarantees that category holds one of five values, not that the classification is right. If needs_human comes back false, whether a person truly doesn't need to look is another matter.

So, separately from the schema, prepare the following:

  • Value checks: Verify business rules in code, such as amounts not being negative or dates not being too far in the past.
  • Escape routes: Put options in the schema that let the AI avoid forcing a decision, like "Other," "null," or "when in doubt, true."
  • A way to check: Keep the reason field and have a person spot-check a share of the results.

Summary

"Just return X" fails not because the prompt is badly written, but because you are trying to set the shape by asking. If a program uses the output, define the shape with a schema and write per-value instructions in descriptions. What remains in the prompt body is just the purpose and background of the task.

At Vitalify Asia, we develop systems and services that build generative AI into business workflows. If you are designing how AI output connects to the processing that follows, such as classifying inquiries or extracting fields from documents, feel free to contact us.

Since 2008, VFA has been involved in more than 1,000 development projects. Many of them are not publicly listed, so please feel free to reach out for details.

Vitalify Asia development portfolio


Each service's specifications are continuously updated. This article reflects information as of November 20, 2026.

Vitalify Asia Co., Ltd. https://vitalify.asia/

Struggling to turn ideas into reality? With a proven track record of over 1,000 clients, our agile and flexible team will accelerate your business growth.

Back to Blog
I'm Duper, ask me anything!