Specifying Output Format
Tell the model exactly what the reply should contain, a full file, a diff, a snippet, or JSON, so it drops straight into your workflow.
TL;DR
- State the exact output you want: full file, unified diff, snippet, or structured JSON.
- The right format depends on how you will consume the result, by eye, by patch, or by program.
- Naming the format and saying 'nothing else' removes the cleanup step.
Pick By Consumer
For Your EyesA snippet or full file is fine when you will read and paste it yourself.
"Return the function in one code block."For A PatchA diff applies cleanly and shows exactly what changed.
"Return a unified diff against the
current file."For A ProgramStrict JSON (or another machine format) when output is parsed downstream.
"Return only JSON matching this schema."Code Formats
Full FileBest for new or small files; the model returns the whole thing.
"Output the complete file, ready to save."Changed Function OnlyFor edits, ask for just the function that changed to save context.
"Return only the updated handler,
not the whole module."Unified DiffShows additions and removals for quick, safe review.
"Give a git-style diff with 3 lines
of context."Structured Output
Describe The SchemaSpell out keys, types, and whether fields are optional.
{ "name": string,
"deps": string[],
"risky": boolean }Give One ExampleA single example object removes ambiguity about shape.
{ "name": "auth", "deps": ["jwt"],
"risky": true }Forbid ExtrasSay no prose and no markdown fences so a parser does not choke.
"Return only the JSON. No markdown,
no commentary."Trim The Noise
Say 'Only'The word 'only' is the fastest way to cut explanation you do not want.
"Return only the code."Separate SectionsIf you want notes too, ask for them labeled and after the code.
"Code first, then a 1-line rationale."Set LengthCap explanations so the reply stays scannable.
"Explain in at most two sentences."Tips
- For edits to existing code, ask for a diff or just the changed function so you can see what moved.
- When output feeds a script, demand strict JSON with a named schema and 'no prose, no markdown'.
Warnings
- Without a format you get prose wrapped around code that you must trim before using.
- Asking for a 'full file' of a large module wastes context and risks the model dropping parts.
In Practice
One bug fix requested three ways, for reading, for patching, and for a tool that logs changes. Matching the format to the consumer removes manual reshaping each time.
- The review format returns only the changed function for quick reading.
- The patch format returns a unified diff you can apply directly.
- The machine format returns strict JSON describing the change for a log.
- Each prompt ends by forbidding anything the consumer does not need.
# FOR REVIEW
Fix the off-by-one in paginate(). Return only
the corrected function, nothing else.
# FOR PATCHING
Fix the off-by-one in paginate(). Return a
unified diff against the current file, 3 lines
of context, no prose.
# FOR A TOOL
Fix the off-by-one in paginate(). Return only
JSON: { "file": string, "summary": string,
"linesChanged": number }. No markdown.FAQ
For small files or new files, a full file is clear. For edits to larger files, ask for a unified diff or just the changed function, so you can review exactly what changed instead of diffing a whole file by eye.
Describe the exact schema, give one example object, and say 'return only valid JSON, no markdown, no commentary'. If the tool supports a structured-output or JSON mode, enable it, and still validate the result before trusting it.
A diff shows intent: you see what was added, removed, or moved without re-reading the whole file. It makes review faster and catches unintended changes the model slipped in.
Yes, but separate it. For example, 'return the function, then a one-line note on the trade-off'. Keeping sections labeled lets you take the code and ignore the rest, or vice versa.