Lesson 8 / 29

Controlling the Output Format

Ask for lists, tables, JSON or fixed templates.

Describe the shape, show a sample

State the format explicitly: "a Markdown table with columns Name, Risk, Fix", "exactly 3 bullet points", "JSON with keys title and tags". Showing a sample output is even stronger. Specify length (words, sentences, bullets), order, and what to do when information is missing ("write unknown, do not guess"). If another program will read the reply, request a machine-readable format and validate it in code (next section) rather than trusting it. Ask for the answer only, without a friendly preamble, when the output feeds a pipeline.

Prefill the start of the reply

Where the API allows it, begin the assistant message with { or | to push the model straight into JSON or a table.

Quick check: If a program reads the reply, what should you do?

  • Ask for a poem
  • Hope the format is right
  • Request a machine-readable format and validate it in code
  • Disable the system prompt
Answer

Request a machine-readable format and validate it in code — Models sometimes deviate, so verify before using.