Skip to content

Build a Small Test Set for an AI Prompt

A five-example test set can expose whether a support-classification prompt handles clear requests, ambiguity, and missing details consistently. This walkthrough gives you five labeled fixtures, a copyable prompt, and a small Python script that checks whether the model’s predicted labels match the expected labels.

Prerequisites and intended result

You need ChatGPT and Python 3.9 or later. The scorer uses only Python’s standard library; it does not call an AI service. Its input is a fixture file containing the expected labels and a predictions file containing one JSON object per example.

This test uses five labels: account, billing, shipping, technical, and needs_clarification. The last label is an intentional safe outcome when a message is ambiguous or lacks enough information. ChatGPT Projects can keep related chats, files, and project instructions together; availability depends on plan and workspace settings. To add project instructions, open the project’s more-options menu and choose Project settings. Those instructions apply only within that project. (Projects in ChatGPT)

Worked example: fixtures and prompt

The examples below are invented sample data. Save them as fixtures.json. The labels encode the intended policy: when a message plausibly fits two categories, ask which issue the customer wants handled first; when details are missing, ask for the information needed to route it.

Example input: the five ticket messages appear in the fixture file, including “I was charged after my plan ended, and I can’t log in to cancel” and the underspecified “It stopped working.”

[
  {"id":"T-101","text":"My password reset link expired. Please send a new one.","expected":"account"},
  {"id":"T-102","text":"I was charged twice for the same invoice.","expected":"billing"},
  {"id":"T-103","text":"The tracking page says delivered, but there is no package here.","expected":"shipping"},
  {"id":"T-104","text":"I was charged after my plan ended, and I can't log in to cancel.","expected":"needs_clarification"},
  {"id":"T-105","text":"It stopped working.","expected":"needs_clarification"}
]

Paste this prompt into a new chat, then paste the five id and text values in place of <tickets>. If you use a Project, you can instead save this as project instructions and provide the ticket list in a project chat. OpenAI recommends clear, specific prompts, prioritizing the task, and refining prompts iteratively. (How do I create a good prompt for an AI model?)

Classify each support ticket using exactly one label:
account, billing, shipping, technical, needs_clarification.

Use needs_clarification if the message is too vague to route or could
reasonably describe more than one category. Do not guess. For each such
ticket, ask one short question that would resolve the uncertainty.
For other tickets, set question to an empty string.

Return exactly one JSON object per ticket, one per line, with these keys:
id, label, question. Do not add Markdown or introductory text.

Tickets:
< tickets go here >

The expected labels are account, billing, shipping, needs_clarification, and needs_clarification, in fixture order. The sample prediction file below is illustrative output; it was not produced by running a model. Save it as predictions.jsonl.

Expected output:

{"id":"T-101","label":"account","question":""}
{"id":"T-102","label":"billing","question":""}
{"id":"T-103","label":"shipping","question":""}
{"id":"T-104","label":"needs_clarification","question":"Would you like help with the charge or regaining account access first?"}
{"id":"T-105","label":"needs_clarification","question":"What stopped working, and what device or error message are you seeing?"}

Score the labels locally

Save this scorer as score.py. Run it from the same folder as the two data files with python score.py. It reports exact label accuracy and flags malformed JSON, duplicate IDs, missing tickets, and unexpected IDs. It checks labels only; it does not judge whether clarification questions are useful.

import json
from pathlib import Path

VALID_LABELS = {
    "account",
    "billing",
    "shipping",
    "technical",
    "needs_clarification",
}


def read_fixtures(path):
    with path.open(encoding="utf-8") as file:
        data = json.load(file)
    return {item["id"]: item["expected"] for item in data}


def read_predictions(path):
    predictions = {}
    errors = []

    with path.open(encoding="utf-8") as file:
        for line_number, line in enumerate(file, start=1):
            if not line.strip():
                continue
            try:
                item = json.loads(line)
            except json.JSONDecodeError as exc:
                errors.append(f"Line {line_number}: invalid JSON ({exc.msg})")
                continue

            ticket_id = item.get("id")
            label = item.get("label")

            if not isinstance(ticket_id, str):
                errors.append(f"Line {line_number}: missing string id")
                continue
            if ticket_id in predictions:
                errors.append(f"Line {line_number}: duplicate id {ticket_id}")
                continue
            if label not in VALID_LABELS:
                errors.append(f"Line {line_number}: invalid label for {ticket_id}")
                continue

            predictions[ticket_id] = label

    return predictions, errors


def main():
    expected = read_fixtures(Path("fixtures.json"))
    predicted, errors = read_predictions(Path("predictions.jsonl"))

    for error in errors:
        print(f"ERROR: {error}")

    missing = sorted(set(expected) - set(predicted))
    unexpected = sorted(set(predicted) - set(expected))

    for ticket_id in missing:
        print(f"MISSING: {ticket_id}")
    for ticket_id in unexpected:
        print(f"UNEXPECTED: {ticket_id}")

    correct = sum(
        predicted.get(ticket_id) == label
        for ticket_id, label in expected.items()
    )
    total = len(expected)
    print(f"Label accuracy: {correct}/{total} ({correct / total:.0%})")


if __name__ == "__main__":
    main()

Verify the result: with the illustrative predictions above, the scorer should report Label accuracy: 5/5 (100%) and no errors. Then inspect T-104 and T-105 yourself: each should have a nonempty question, while the other three should have an empty one. The script does not validate that question rule, so this manual check is part of acceptance.

Diagnose failures and recover

If accuracy is below 5/5, use the printed ticket IDs to find the mismatch. If the model labels T-104 as billing or account, strengthen the prompt’s ambiguity rule with that exact example, then rerun all five fixtures. If T-105 gets a specific label, say explicitly that a message with no object or symptom must receive needs_clarification.

A parse error usually means the model added prose, used a Markdown code fence, or returned a JSON array instead of one object per line. Repeat the request with “Return only JSONL: one valid JSON object on each line,” replace the predictions file, and score again. This five-item set is useful for checking a prompt revision, but it is not enough to establish real-world performance across varied customers, languages, or edge cases.

Frequently Asked Questions (FAQ)

Q1) Should I treat every unclear request as needs_clarification?

Use that label when the missing detail changes where the ticket should go or what action should happen. If your support policy specifies a default route, add that rule and create a fixture for it. For urgent or high-impact requests, define a human escalation path instead of relying on this small test.

Q2) What if the model adds explanations or wraps its answer in a code fence?

That output violates the requested format and may not be accepted by your downstream parser. Ask again for one JSON object per line with no surrounding text, then replace the predictions file and rerun the scorer. Keep the failed response separately if you need to diagnose recurring formatting problems.

Q3) Can these five fixtures prove the prompt is reliable?

No; they check a handful of intended cases, not the full distribution of incoming tickets. Add anonymized, representative examples for each category, including confusing overlaps and uncommon but consequential cases. The method is unsuitable as the sole quality check for automatic routing where a wrong category could cause serious harm; use policy review and human oversight for those decisions.

Leave a comment