Skip to content
mentoor

Topic 1 of 5 · 4 min read

Instructions at the right altitude

Goal: Rewrite an over-specified or vague agent system prompt into clear heuristics that also cover unseen cases.

A good agent prompt sits between a rulebook and a slogan: it gives the agent the goal, the reasons and a few firm heuristics, so it can handle cases you never listed.

Check yourself · 1 of 3

A system prompt lists 40 if-then rules, and the agent stalls on a case none of them covers. What is the most likely cause?

Choose one answer

Why altitude matters

An agent runs for dozens of turns and meets situations you did not predict. Two failures follow. A prompt that is too low (long chains of "if the user says X, do Y") breaks the first time reality differs from the list, and the agent either freezes or applies a rule where it does not fit. A prompt that is too high ("be helpful and careful") gives the model nothing to act on, so it falls back on its own habits. Anthropic's context engineering article describes this as finding the smallest set of high-signal instructions that still steer behaviour.

How to find the right level

  1. State the job and who it is for. One short paragraph: what the agent does, for whom, and what a good result looks like.
  2. Give the reason with each rule. "Never edit files under migrations/ because they are already applied in production" lets the agent extend the rule to schema.sql. A bare rule cannot be extended.
  3. Prefer a heuristic to a script. "If a change touches more than one module, write a short plan first" covers cases a list of file names never will.
  4. Keep hard rules for hard limits. Security, money, deletion and legal limits stay as short, flat statements. Everything else is guidance.
  5. Show one or two examples, not twenty. Examples pull behaviour towards themselves. A few varied, canonical ones work better than every edge case.
  6. Cut what the model already does. If the agent never writes in the wrong language, do not tell it to write in the right one.

Before and after

Too low:

If the test fails, run it again. If it fails twice, read the stack trace.
If the trace mentions auth.ts, open auth.ts. If it mentions db.ts, open db.ts.
If the file is longer than 300 lines, read only the first 100 lines.

At the right altitude:

You fix failing tests in this repository. Find the cause before changing
code: read the failing assertion and the code it exercises. Change as little
as possible. Never weaken or delete a test to make it pass; if you believe
the test is wrong, stop and say why.

The second version is shorter and handles a failure in billing.ts, which the first never mentions.

What goes wrong

  • Rules that contradict each other. "Always ask before editing" and "work autonomously" in one prompt make behaviour random between runs. Read the whole prompt once for conflicts.
  • Rules added after every incident. Each patch fixes one case and the prompt grows into a pile nobody can reason about. Fold related patches into one principle.
  • Shouting. Capital letters and "CRITICAL" on ten rules make all of them equal. Reserve emphasis for the one or two limits that really cannot be crossed.

Examples

A rule that carries its reason

Weak: "Do not touch the legacy/ folder."

Better: "Do not edit legacy/: it is generated from the billing vendor's schema and edits are overwritten on the next sync. If a fix seems to need a change there, report it instead."

The second version also stops the agent from patching vendor/generated/, because the reason applies there too.

Collapsing patches into a principle

A prompt has grown three patches: "do not delete the .env file", "do not overwrite config.yml" and "do not remove the lockfile". One principle covers all three and more: "Do not delete or overwrite files you did not create in this session without asking, unless the task names them."

Key points

  • Too low an altitude means brittle if-else rules; too high means slogans the model cannot act on.
  • Give the reason with each rule so the agent can apply it to cases you did not list.
  • Use short flat statements for hard limits and heuristics for everything else.
  • A few varied examples steer better than many near-identical ones, which the agent copies too literally.
  • Read the finished prompt for contradictions and for lines that only restate what the model already does.

Common mistakes

  • Writing a decision tree for situations you have seen, then trusting it for situations you have not.
  • Adding a new rule after each bad run instead of rewriting the principle that was unclear.
  • Using capitals and "never" on every line, so the real hard limits no longer stand out.
  • Leaving contradictory instructions in different parts of the prompt, for example "ask first" and "do not interrupt the user".

Check yourself · 2 of 3

Which rewrite of "Do not edit the migrations folder" is best for an agent that works for many turns?

Choose one answer

Check yourself · 3 of 3

Your prompt says "Always ask before changing code" in one section and "Work without interrupting the user" in another. What do you do?

Choose one answer

Practice items, not counted towards your mastery.

Start here