← All news

News / Learn / Prompt engineering

How do you test and improve a prompt?

You'll be able to build a small test set, score prompt versions against it, and change prompts with evidence.

A prompt is a piece of text that you change and hope will work better. Testing means you run that text against a fixed set of inputs and check the outputs. Improving means you change one thing, run the tests again, and keep the change only if the results get better.

Prompts that look fine on one example often fail on the next. Users send messy, unexpected inputs. A repeatable test lets you catch regressions before users do. It also stops you from fixing one case while breaking five others.

Start by collecting real inputs. Use examples from logs, support tickets, or your own guesses about what users will type. Include easy cases, hard cases, and edge cases such as empty input, very long input, and off-topic input. Write down what a good output looks like for each one. These written expectations are your test cases.

Next, define how you will score an output. Some checks are exact: does the output parse as JSON, does it contain a required field, does it stay under a length limit. Other checks need judgment: is the answer correct, is the tone right. For judgment checks you can use a human reviewer, or a second model that grades the output against a rubric. This second approach is often called LLM-as-a-judge. Check the grader on a few cases yourself, because a grader can be wrong too.

Run every prompt version against the full set, not a handful of examples. Model output varies between runs, so set temperature low for testing and run each case more than once when results matter. Record the score for each version and each case. Keep the prompt version, the model name, and the settings together so you can reproduce any result later.

When you improve a prompt, change one thing at a time. Add a rule, or move an instruction, or add one example, then rerun the suite. If the score rises without hurting other cases, keep the change. If it falls, revert. Over time your test set grows as you find new failures. Each real failure you fix becomes a permanent test case.

A small test harness in Python. Each case has an input and a check. The check returns True or False.

import json

cases = [
    {"input": "Order 1042 has not arrived", "must_have": "category"},
    {"input": "", "must_have": "error"},
]

def check(output: str, must_have: str) -> bool:
    try:
        data = json.loads(output)
    except json.JSONDecodeError:
        return False
    return must_have in data

def run_suite(call_model, prompt_version: str) -> float:
    passed = 0
    for case in cases:
        output = call_model(prompt_version, case["input"])
        if check(output, case["must_have"]):
            passed += 1
    return passed / len(cases)

# score = run_suite(my_model_call, PROMPT_V2)
# print(f"Pass rate: {score:.0%}")

A short sketch to show the idea. Check the official docs of the tool you use.

  • Testing on only the examples you wrote the prompt with Keep a held-out set of inputs you never used while tuning. Otherwise the score measures memorization, not quality.
  • Changing many things at once Change one instruction or example per run. If you change five things and the score moves, you will not know which change caused it.
  • Trusting a single run Model output varies. Run each case several times, or use a fixed low temperature, before deciding a change helped.
  • Using an unchecked grader Before you rely on a model judge, grade a sample by hand and confirm the judge agrees with you.

Learn about eval design: how to split data, how to measure agreement between graders, and how to track scores across model changes. Look into regression testing for prompts so new releases do not silently break working behavior.

How many test cases do I need?

Start with about 20 to 50 cases that cover your main inputs and known failures. Add cases every time a real failure appears. Quality of cases matters more than count.

Should I store prompts in code or in a separate tool?

Either works. Store each prompt version with an identifier, so every test result points to the exact text that produced it.

Can I trust a model to grade another model's output?

Only after you check it. Compare the grader's verdicts with your own on a sample. Use a clear rubric and ask for a short reason with each verdict.

What temperature should I use for testing?

Use a low value so results are more repeatable. Then test a higher value separately if your product will run at that setting.

Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.