Skip to content

Lesson 22 ยท Safety and Production

Testing and Evaluating Your OpenAI App

Test OpenAI apps with fake clients, a labeled evaluation set, code checks and rubric grading, then compare prompt and model changes before release.

Normal code gives the same output for the same input, so a test can expect an exact result. Model output varies, and "correct" is often a matter of degree. That does not mean you cannot test it. You need two kinds of tests: fast code tests that never call the model, and evaluations that measure real model behavior on a set of examples.

OpenAI announced that its Evals API and dashboard, datasets and related tools would shut down on November 30, 2026, and pointed users to tools such as Promptfoo. If you find a tutorial built on the old Evals features, do not follow it. The method below works with any tool, or with a few lines of your own code.

Test your code without the model

Pass the client into your function. In tests, give it a fake. Such tests are fast, free and repeatable.

Python Stand-in: test with a fake client

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

These tests check your logic: parsing, statuses, tool dispatch and error handling. They say nothing about model quality.

Build an evaluation set

An evaluation set is a list of inputs with expectations. Start small, perhaps 30 cases, and grow it.

  • Typical cases from real use (remove personal data first).
  • Edge cases: empty input, very long input, mixed languages, typos.
  • Cases where the right answer is "I do not know."
  • Harmful or tricky input, including prompt injection attempts.
  • Every important bug you have found.

Store it in version control next to your prompts, for example as JSONL.

Grade the results

Grader Good for Watch out
Exact match Labels, IDs Too strict for free text
Code checks Format, length, required facts, schema Cannot judge tone or meaning
Human review Quality and safety Slow, needs clear rules
Model as judge Larger volumes of text Can be biased or wrong

Use code checks wherever you can. If a model grades answers, give it a clear rubric and compare its grades with human grades on a sample first. See LLM as judge and rubrics.

Report more than one number

An average can hide a serious failure. Report results by category, and mark cases that must never fail. This script compares two versions using invented pass and fail data.

Python Compare two prompt versions

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Version 2 has a higher total, but it breaks a critical case. A good release rule would block it. Always look at which cases changed, not only the totals.

Handle variation

Because output varies, one run is not proof. For important cases, run several times and record how often they pass. With a small set, a difference of one or two cases may be chance. Read the actual outputs of failures; numbers alone do not tell you why.

When to run evaluations

Run them whenever you change:

  • The prompt or instructions.
  • The model or reasoning effort.
  • Tool definitions or schemas.
  • Chunking, search or filters.
  • The SDK, in major updates.

Also run them on a schedule, because services and data can change. Keep results with the date, model ID and prompt version. Evaluations cost money, so keep a small quick set for every change and a larger set before releases.

Test the whole system

A good model reply is not enough if your retrieval finds the wrong page or a tool runs twice. Test these separately and together:

  • Retrieval: does the right document appear?
  • Tool use: is the right tool chosen with valid arguments?
  • Permissions: can one user reach another user's data?
  • Failures: what happens on timeouts, refusals and invalid output?

Learn from production

With permission and privacy protection, sample real conversations for review. Track simple signals such as user ratings, retries, hand-offs to humans and validation failures. Add the interesting cases to your evaluation set. See building a prompt test set.

Do not tune a prompt until it passes only your test cases. Keep some cases aside that you do not look at while editing, and check them before release.

Keep results you can compare

For each run, save the date, the code version, the prompt version, the model ID, the settings and one row per case with the output and grades. With this record you can answer "when did this start failing?" and compare any two runs. Keep the outputs, not only the scores, but protect them if they contain sensitive text.

When a case fails, decide whether the output, the expectation or the grader is wrong. Fixing a bad expectation is legitimate; quietly weakening a test so a release can pass is not. Note why you changed any test. Remove duplicates from time to time, so one kind of input does not dominate the score.

Share a short summary with the people who decide on releases: what improved, what got worse and which risks remain untested.

Common mistakes

  • Expecting one exact sentence from a model, so that harmless wording changes fail the test.
  • Using only easy examples that you wrote yourself, which makes every version look good.
  • Changing the prompt, model and test set at the same time, so you cannot tell what caused a difference.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a test with a fake client check?

    No model runs, so it only tests your logic.
  2. 2. Why can a higher overall pass rate still be unacceptable?

    Critical cases need their own rules.
  3. 3. What should you do before trusting a model as a grader?

    A judge can be wrong, so you should measure how well it agrees with people.
  4. 4. What happened to OpenAI's hosted Evals tools?

    Use other tools or your own test code.

Summary

  • Test your code with fake clients, and measure model behavior with evaluations.
  • Build a varied, versioned test set that includes hard and unsafe cases.
  • Prefer code checks, and calibrate human or model grading.
  • Report by category and protect critical cases.
  • Rerun after every change and learn from real use.

Next: Production Checklist and Data Privacy

Your progress is saved in this browser. No account needed.