ClaudePrompt basicsLevel 1: Basic prompts

How Do You Get Claude to Answer in a Set Format?

Name the format exactly: columns, number of items, length, and what goes before and after it. In a chat, that's usually enough. On the API, use structured outputs when a program will read the result, since a schema is enforced and a request in words isn't.

Prompt to copy
[Your request.]

Format:
- A markdown table with these columns: [column 1], [column 2], [column 3].
- One row per [item], with at most [N] rows, sorted by [field].
- Keep each cell under [12] words.
- After the table, write one sentence saying which row you'd pick and why.

Start with the table, with no introduction. If a value is unknown, write "unknown" rather than guessing.
Claude can driftAPI enforces it
  • "Use JSON"
  • Named fields
  • XML-tagged sections
  • Structured outputs
Rule of thumb, not an Anthropic chart. Positions show rough order only. Only structured outputs enforce a schema, and a refusal or max_tokens stop can still miss it.

Try it now

  1. 1Pick an answer you recently had to reformat, and write down exactly what you changed.
  2. 2Paste the prompt above, with those changes as format rules, into a new chat.
  3. 3If you want an actual file, check that Code execution and file creation is on at Settings > Capabilities, then ask for the file type by name.
  4. 4You'll know it worked when you can move the result into its destination without editing the structure.

Use it when

When the answer has somewhere to go: a spreadsheet, a slide, a code file, a document template, or a comparison across several runs. Also use it when you keep reformatting Claude's answers by hand.

Skip it when

Early exploring, when you don't yet know the shape of the answer. A forced table can hide the point that doesn't fit in a column. Long-form writing is another. Anthropic's docs note that heavy bullet formatting can fragment ideas, and they offer a sample prompt to reduce it.

Why it works

Anthropic's docs list a few ways to steer formatting. Say what the output should be, rather than what to avoid. Use XML tags to mark sections. Match your prompt's style to the output you want, since a prompt written in markdown can pull the answer toward markdown. Give explicit detail when you care. Default style varies by model too: Anthropic's docs say Opus 5 runs longer by default and that effort doesn't reliably change its length, while Fable 5.1 formats less than earlier models. So state length and structure rather than relying on defaults. On the API, send your schema in output_config.format with type: "json_schema", and the response is held to that shape.

Example

Say you're comparing three accounting tools. Ask for a table with the columns tool, monthly price, free trial length and main limit, with one row per tool, and "unknown" for anything Claude can't confirm. With web search on, you can also ask for a source column. The table pastes into your document, and the "unknown" cells show you what to look up.

Going further

An older trick no longer works. Prefilling the start of Claude's reply returns a 400 error on the 4.6 generation and later, and Anthropic points to structured outputs or plain instructions instead. Structured outputs have limits of their own. They reject numeric and string constraints such as minimum and maxLength. The output can still miss your schema after a refusal or when stop_reason is max_tokens. They also can't be combined with citations, and the API returns a 400 error if you try. For JSON that needs some working out, Anthropic's Sonnet 5.5 guide suggests adding a line that asks the model to think the problem through first, since it can otherwise answer without thinking at low and medium effort.

Common mistakes

  • Asking for JSON without naming the fields, so the shape changes between runs.
  • Parsing a request-in-words JSON answer as if all of it were JSON. Anthropic's Sonnet 5.5 guide says the model may work through the problem in the text first and put the JSON at the end.
  • Accepting valid JSON from a response that stopped at max_tokens. Anthropic says to treat it as failed and retry.
  • Setting a format and then asking for lots of explanation in the same answer. Say where the explanation goes, or ask for it afterward.

Sources

Checked 6 November 2026. Products change often, so confirm details with the vendor.

Related

Beyond the course