Prompt craft
M04 · 10 min

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

  1. 01

    Role / job

    What kind of help: implement, debug, review, scaffold.

  2. 02

    Context

    Stack, file paths, snippets, error text, product goal.

  3. 03

    Goal

    Observable behavior after the change.

  4. 04

    Constraints

    Don’t touch X. Preserve API. Mobile-first. No new deps.

  5. 05

    Output shape

    Patch only / full file / plan / bullet summary.

  6. 06

    Verification

    Commands to run; what “done” looks like.

Weak
Strong
Make the dashboard better and modern
In src/routes/dashboard.tsx only: add a revenue sparkline from existing stats[]; empty state if length 0; no new chart library
Fix the bug
Error: [paste]. Command: npm test. Suspect files: a.ts, b.ts. Smallest fix; do not reformat untouched code

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
Next