← Practice guides

How to write prompts for an AI coding agent

Updated

A strong prompt for an AI coding agent states what you ran, what you expected, the few lines of output that matter, what you think is wrong, and the smallest next step. That gives the agent a target it can check instead of a guess. It also keeps the conversation short, because everything you paste is sent again with every later request.

The patterns below are the five kinds of request that PraxisAI's prompt coach flags in practice reports, with the rewrite it suggests for each. They are habits, not rules a model enforces, so they apply in any agent or editor.

Five prompts that waste a round

Each of these hands the agent work without the information it needs to do that work well. The agent fills the gap by guessing, and the guess usually costs another edit and another test run.

  • Raw error paste: a full traceback with no command, expectation or suspicion. The agent re-reads files and retries its last fix.
  • Code dump: a snippet with "use this". The agent applies it like a typist and cannot catch a mistake in it.
  • Pasted problem statement: the issue text with no plan. The agent explores widely and commits to its first guess.
  • Low-effort nudge: "still broken" or "try again". No new information, so the agent retries a variant of the same idea.
  • Re-ask: the same request sent again. Same kind of answer, larger context.

When a test fails, send evidence and a hypothesis

Trim the output to the lines that locate the failure: the test, the last frame or two in your code, and the error line. Say which command produced it and what you expected. Then commit to a hypothesis, even a rough one, and ask the agent to confirm or rule it out before editing.

The error type often points at the cause. An import or configuration error that fires before any test runs usually means the command or setup is wrong, not the code. Saying so stops the agent from "fixing" code that was never the problem.

I ran `pytest tests/test_dates.py` after your change to `utils/dates.py`
and expected it to pass. It fails with `AssertionError`:

  tests/test_dates.py:42: in test_two_digit_year
  E   AssertionError: assert 2069 == 1969

My hypothesis: the fix returns the wrong century for two-digit years.
Confirm or rule that out first, then make the smallest change that fixes it
and re-run only tests/test_dates.py.

Turn an issue into read, propose, implement

Restate the requirement in one sentence of your own. Then split the work: ask the agent to read the relevant module and name the tests that cover it without editing, propose the change in two or three lines including boundary cases, and only after you agree, implement it with a regression test.

Keeping each turn small lets you reject a wrong approach before it is written instead of steering after it is in the code. Add the constraints you know, such as a public API or existing tests that must not change.

Share code with intent, and retry with a diagnosis

When you have code in mind, name the file and function, state the behavior it must achieve, and ask the agent to check your snippet against the existing tests and edge cases before applying it. Say what done means and ask to see the diff. The decision stays yours, which is exactly what an interviewer will ask you about.

When an attempt fails, do not send the same request again. Quote the evidence, such as the pass and fail counts, and ask the agent to explain in two sentences why it still fails before it edits anything. If you are re-asking, say what was wrong with the first attempt and how you will know the next one worked. A short diagnosis is the cheapest way out of a loop.

Practice the habit, then check the record

Prompting improves fastest when you can read your own prompts afterward next to what each one cost and what followed. Pick one pattern from the list above, avoid it deliberately on your next unfamiliar task, and compare the two records.

In PraxisAI, detailed practice reports show each flagged prompt, a suggested rewrite with gaps only you can fill, and an estimate of the tokens it cost above the round's typical turn. The rewrites are built from rules and your round's own content. They show a better way to ask, not the only correct one.