Anatomy of a coding prompt
Best prompts name files, behavior, constraints, tests, output format, and uncertainty.
Research and field practice agree: Grok (and any coding agent) performs when prompts are operational, not literary. Include target files, expected behavior, constraints, test command, output format, and a requirement to explain uncertainty before editing.
Six fields
- 01
Role / job
What kind of help: implement, debug, review, scaffold.
- 02
Context
Stack, file paths, snippets, error text, product goal.
- 03
Goal
Observable behavior after the change.
- 04
Constraints
Don’t touch X. Preserve API. Mobile-first. No new deps.
- 05
Output shape
Patch only / full file / plan / bullet summary.
- 06
Verification
Commands to run; what “done” looks like.
Exercise
Rewrite a weak prompt
Take “build me a todo app with AI vibes” and rewrite it using all six fields.
- All six fields present
- Constraints include at least one must-NOT
- Verification named