Skip to main content

Prompt guides

How to write a prompt that asks for structured output

Practical guidance for writing a prompt that reliably asks for JSON, a table, or another fixed format — the companion piece to what structured AI outputs are and why prompting alone does not guarantee valid structure.

All prompt guides · Last reviewed:

Describe the exact shape you want, not just the format name

Saying "return this as JSON" is a start, but naming the fields, their order, and their types is what actually removes ambiguity — "return a JSON object with a string field called title and an array field called steps, where each step is a string" leaves far less for the model to guess than "return JSON with the title and the steps." The same applies to a table: name the columns and what belongs in each one rather than assuming the model will pick the same breakdown you have in mind.

Show one example of the exact output you want

A single example of the finished shape — a short sample JSON object, or one row of the table — often removes more ambiguity than another paragraph of description would, for the same reason an example helps in few-shot prompting, linked below. This matters most when the format has a quirk that is easy to describe imprecisely, like whether a field is optional or how a missing value should be represented.

What a well-written prompt does not guarantee here

A carefully written prompt makes valid, well-shaped output more likely, but it does not guarantee it — a model can still return malformed JSON, an extra field, or prose wrapped around the structure you asked for, especially on a longer or more complex response. See what are structured AI outputs, linked below, for the technical mechanisms — like schema-constrained generation — that exist specifically because prompting alone is not a reliable guarantee, and for what ClawAI does differently from asking nicely in a prompt.

Questions people ask

Is asking nicely in a prompt enough to guarantee valid JSON?
No — a well-written prompt makes it more likely, not certain. See what are structured AI outputs, linked below, for the mechanisms that exist because prompting alone does not reliably guarantee valid structure.
Should I describe the format or show an example?
Both, when the format has any ambiguity — a precise description of the fields plus one example of the finished shape covers more cases than either alone. See few-shot prompting, linked below, for how to choose a good example.
What is the difference between this guide and what are structured AI outputs?
That page explains the technical mechanism behind reliable structured output; this page is the practical companion — how to write the prompt itself. They are meant to be read together, not as duplicates of each other.

Practice on a real conversation

For output that has to be reliably valid, ClawAI’s structured-output mechanisms (see what are structured AI outputs, linked below) go further than prompt wording alone — this guide covers the prompt-writing half of that picture.