A reliable prompt is not finished when it produces one good answer. It is finished when it performs consistently across representative inputs, handles edge cases, and remains useful after a model, dataset, or application changes. This prompt evaluation framework gives developers a repeatable way to create test sets, define scoring criteria, compare prompt versions, and decide what to improve next.
Overview
Prompt evaluation is the practice of testing an LLM prompt against known inputs and judging the resulting outputs against explicit requirements. It is a core part of prompt engineering for developers because an output that looks acceptable in a demonstration may fail on ambiguous requests, long context, unusual formatting, or sensitive cases.
The objective is not to find a universally “best” prompt. The objective is to find the prompt that best satisfies the requirements of a particular application. Those requirements might include factual accuracy, instruction following, valid JSON, appropriate tone, low latency, predictable refusal behavior, or compatibility with a downstream parser.
A useful evaluation loop has five stages:
- Define what a successful output must do.
- Build a representative test set.
- Run the same cases through a prompt or model version.
- Score the outputs using consistent criteria.
- Review failures, change one variable, and run the tests again.
This process works for simple classification prompts, retrieval-augmented generation, structured extraction, customer-support workflows, and multi-step AI agents. For examples of production-oriented prompt patterns, see AI prompt templates for developers.
Template structure
Store each evaluation as a small, versioned specification rather than as an informal collection of sample conversations. The following structure is suitable for a spreadsheet, JSON file, database table, or evaluation tool.
1. Task definition
State the task in one sentence and identify the output contract. For example: “Extract the customer’s order number and issue type from a support message and return valid JSON.” Include constraints such as permitted labels, required fields, maximum length, or citation requirements.
2. Test case record
Each case should contain:
- Case ID: A stable identifier such as support-014.
- Input: The exact user message, document, or retrieved context.
- Expected properties: The characteristics a correct answer must have.
- Reference answer: An example answer when one can be defined.
- Category: Normal, ambiguous, adversarial, long-context, or edge case.
- Priority: The business or technical impact if the case fails.
3. Prompt version
Record the system instructions, user template, few-shot examples, tool definitions, model identifier, relevant settings, and date of the run. If the prompt uses retrieval, also record the retrieved context or the retrieval configuration. Without this information, a later result may be impossible to reproduce.
4. Scoring rubric
Use criteria that map directly to the task. A general rubric might score each output from zero to two:
- Correctness: Does the answer match the available evidence?
- Completeness: Are all required parts present?
- Instruction following: Does it obey the requested format and constraints?
- Robustness: Does it handle ambiguity or missing information appropriately?
- Safety and scope: Does it avoid unsupported claims or actions outside the task?
Define what each score means before testing. For example, a score of two for format could mean valid parseable JSON with every required field, while a score of one could mean useful content with a minor formatting error.
5. Run summary
Track pass rate, average criterion scores, critical failures, token usage when relevant, latency when relevant, and the prompt version. Keep individual output samples alongside aggregate results. Averages can hide a small number of severe failures.
How to customize
Start with the failure that matters most to your application, not with a long list of abstract quality goals. If an application passes output directly into code, schema validity may be a hard gate. If it drafts internal summaries, factual consistency and coverage may deserve greater weight than exact wording.
Separate hard requirements from preferences. A hard requirement is binary: the output must contain valid JSON, must not invent a value, or must include a required field. A preference can be graded: concise wording may receive a higher score, but a slightly longer answer can still pass. This distinction prevents a polished style from masking a functional failure.
Build the initial test set from real usage where possible. Include representative easy cases, but deliberately add cases that expose weaknesses:
- Inputs with missing or conflicting information.
- Requests containing irrelevant instructions.
- Different languages, spelling variations, or formatting styles.
- Long inputs near the application’s expected limit.
- Multiple valid answers or unclear user intent.
- Examples that should be rejected, escalated, or answered with uncertainty.
For retrieval-augmented applications, evaluate both retrieval and generation. A prompt cannot produce a supported answer if the needed evidence was not retrieved. Check whether the answer uses the supplied context, distinguishes evidence from inference, and acknowledges when the context is insufficient. The guide to RAG prompt engineering provides patterns that can be adapted into these tests.
Use model-based evaluation carefully. A second model can help assess open-ended qualities such as relevance or clarity, but it should receive a precise rubric and, where possible, structured scoring instructions. Validate automated judgments against human review on a sample. For high-impact workflows, retain human approval for cases where an automated score is uncertain or below the release threshold.
When optimizing a prompt, change one major factor at a time: instructions, examples, output schema, context ordering, or model settings. If several changes are introduced together, you may improve the score without knowing which change helped or created a new regression.
Examples
Structured extraction
Suppose a prompt extracts invoice details. A test record might require an invoice number, total amount, currency, and due date. The evaluation should check whether the JSON parses, whether required keys are present, whether values are copied accurately, and whether absent fields are returned as null rather than guessed. A format-only pass is not enough if the extracted total is wrong.
Sentiment classification
For a sentiment prompt, define the permitted labels and add examples where the emotional tone is mixed, implied, or directed at a product rather than a person. Measure label accuracy, but also test whether the prompt avoids treating a neutral request as negative simply because it contains a complaint-related word. A confidence field can be evaluated for calibration as a separate criterion rather than accepted automatically.
For a broader pattern, compare the evaluation design with the sentiment analysis prompt guide.
Code and SQL generation
For generated code, test syntax, adherence to the requested language, behavior on boundary cases, and whether the answer explains assumptions. For SQL, test whether the query uses the stated schema, handles nulls correctly, and avoids inventing columns. A formatter can confirm basic syntax, but execution against a safe test database or a static checker may reveal logical errors that text review misses.
Prompt regression testing
Keep a fixed regression set of cases that previously failed. Every new prompt version should run against this set before release. Add newly discovered failures rather than replacing older cases. A simple change log can record the hypothesis, the prompt change, the score difference, and any newly introduced failures.
When to update
Revisit the evaluation whenever the conditions around the prompt change. Common triggers include switching models, changing model settings, modifying system instructions, adding tools, changing the retrieval pipeline, updating the output schema, or introducing new user groups and languages.
Update the test set after a real production failure, a support escalation, a new abuse pattern, or a change in business rules. Do not remove a case merely because a prompt now passes it; keep it as a regression check. If the application’s definition of success changes, revise the rubric and record why the threshold changed.
A practical maintenance routine is:
- Run a small smoke set for every prompt change.
- Run the full regression set before release.
- Review low-scoring and high-impact failures manually.
- Compare the candidate with the current version, not just with an old baseline.
- Archive the prompt, test data, rubric, and results together.
Start today with 20 to 50 cases that reflect actual use, including several known edge cases. Write the pass criteria before looking at outputs, run a baseline, and label every failure by type. Then make one focused prompt change and rerun the same cases. Over time, this small evaluation habit becomes a durable prompt testing system: measurable enough to guide optimization, flexible enough to support new models, and practical enough to maintain as the application evolves.