Choosing promptfoo assertions: deterministic or model-graded

Use objective assertions such as equals, regex, is-json and JavaScript checks wherever they can decide, and reserve model graders for qualities no rule can capture. Mixing both keeps evals cheap, repeatable and easier to trust.

On this page

Choosing promptfoo assertions: when a rule is enough and when you need a model grader

Use a deterministic assertion whenever the correct answer can be checked by code, and reserve a model grader for properties that only a reader can judge. A suite that asks a model to grade every output is slow, costs money on each run, and gives different verdicts on the same output from one run to the next. The fix is usually not a new tool but a sorting exercise: go through every test and ask whether a rule written in code would give the same answer a human reviewer would. Most structural and format checks pass that test, and most tone, completeness and faithfulness checks do not.

Assertions are the checks promptfoo runs against each model output. The deterministic family includes equals, contains, icontains, regex, is-json, starts-with, levenshtein and javascript, which run in milliseconds and return the same result every time. The model-graded family, such as llm-rubric, factuality and answer-relevance, sends the output and a grading prompt to a judge model. promptfoo runs locally on your machine and calls the LLM directly, so both families execute from your own environment, and the judge calls are billed by whichever provider you configure. The MIT license and the free Community edition, which includes all LLM evaluation features, are context for adoption, not a reason to choose one assertion type over another.

A practical split works well. Put format, schema, length, required-field and forbidden-string checks in code, because those failures are binary and cheap to detect. Use a javascript assertion when you need to read several fields and compare them, for example that a total equals the sum of line items. Keep model graders for judgments such as whether an answer addresses the question, follows a policy, or stays within the supplied source material. Then run the model-graded assertions only on the cases that passed the deterministic gates, so the judge never scores output that is already malformed.

Before you commit, confirm three things in the promptfoo assertion reference for your version: which assertion types accept a provider override for the grader, how grader prompts are logged so reviewers can audit a verdict, and whether a failed deterministic check short-circuits later assertions in your config. Also decide who owns the judge model choice, because changing it changes pass rates without any change to the application. Treat each model-graded assertion as a measurement with its own variance, and re-run a sample of its verdicts by hand before you trust a threshold.

Assertion types and when each one fits

This table compares deterministic assertions, model-graded assertions and classifier-based checks by what each verifies, what it costs to run, how repeatable it is and where it typically fails. Read each row as a question to ask about a specific output property, then pick the cheapest type that can answer it reliably.

Assertion typeWhat it verifiesCost and repeatabilityTypical failure mode
Deterministic (equals, contains, regex)Exact strings, required substrings or patterns in the outputNo model calls, fast, fully repeatable across runsRejects correct answers phrased differently or breaks on minor wording changes
Deterministic (is-json and format checks)Whether output parses as JSON or matches a expected formatNo model calls, fast, fully repeatablePasses well-formed but wrong content, so it needs a companion check for meaning
JavaScript or Python functionsCustom logic such as field values, ranges, computed properties or business rulesRuns locally, repeatable if the code is deterministic, cost limited to your own computeBrittle parsing of unexpected output shapes, and bugs in the check itself go unnoticed
Classifier-based checksProperties such as toxicity, bias or PII using a trained classifier or moderation serviceUsually lower cost than a model grader, repeatable for a fixed model version, but the classifier may be an external serviceMisses domain-specific issues and reflects the classifier's training data, so results need spot checks
Model-graded (llm-rubric)Whether output meets a natural-language standard you defineEach check calls a grader model, so cost and latency recur on every run, with some variation between runsPasses fluent answers that are wrong, or rewards formatting over substance
Model-graded (factuality)Whether an answer agrees with a supplied reference answerRecurring grader cost, repeatability depends on the reference set qualityPenalizes correct answers that are phrased differently from the reference
Model-graded (G-Eval style criteria)Scores against custom criteria, often with step-by-step gradingHigher grader cost per check than a plain rubric, scores vary between runsScore thresholds set arbitrarily, so small changes flip results
Hybrid suite designObjective checks first, model graders only for properties that need judgmentLowest recurring cost, and the deterministic gates stay stable across runsTeams add model graders for properties a regex could check, raising cost and noise

Which checks should be code, and why that keeps evals stable

The first question for any assertion is whether the output has a checkable form. If it does, a deterministic check is usually the better tool, because it gives the same answer on every run and costs nothing beyond the test itself. The cards below cover the common cases where code is enough.

Exact values and computed totals

When the answer is a known value or a calculation, such as a total that must equal the sum of line items, use javascript or equals rather than asking a model to judge arithmetic. Illustrative example: an invoice-summary prompt must return a total of 1,250.00 for a given input, and a short script can recompute it from the fields the model returned. Confirm that your test data includes the rounding cases your business rules require.

Required fields in structured output

When the output must be JSON with specific keys, is-json checks that it parses, and a field-level JavaScript assertion checks that a named key such as customer_id is present and typed correctly. Illustrative example: an extraction prompt that returns a status field limited to a fixed set of values. Confirm how your application handles extra keys, since a strict schema and a tolerant parser will fail different outputs.

Forbidden strings and refusal phrases

A not-contains or regex assertion can block output that leaks an internal hostname, repeats a system prompt marker, or omits a required refusal phrase. Illustrative example: a support bot must refuse requests for account credentials with a fixed sentence, so a regex can confirm the refusal appears and that no password-like string does. Keep the pattern list in version control so reviewers can see exactly what is blocked.

Format and length limits

Checks such as regex for a date format, a length ceiling, or a required prefix on an identifier cost nothing per run and never drift between model versions. Illustrative example: a generated reference number must match a fixed pattern and stay under a set length, because a downstream system rejects anything else. Write these as the first assertions in a suite so cheap failures stop the expensive grading that follows.

Repeatable results and no grader spend

A deterministic assertion returns the same verdict for the same output, so a failing test points to a real change in the application or the prompt rather than to grader variance. It also adds no model calls, so the cost of a run stays with the target model alone. Ask your team which assertions in the current suite could be replaced by code, and track the pass rate before and after to confirm the swap did not hide a regression.

When a model grader is needed and what it costs you

A model grader is needed when the property you are testing cannot be reduced to a fixed string, pattern, schema or code path. Rules can confirm that an answer is valid JSON or contains a required field, but they cannot judge whether a reply is polite enough for a customer, whether it covers every point in a rubric, or whether a paraphrased answer still means the same thing as the reference. Faithfulness to supplied context is the clearest case in retrieval applications: an answer may be fluent and plausible yet add a claim the retrieved documents never made, and only a grader that reads both the context and the answer can flag it. Use a model grader for these judgments, and keep objective checks in place for everything they can verify.

Model-graded assertions have costs that deterministic ones do not. Each run calls a grader model in addition to the model under test, so every test case adds model calls, latency and token spend, and the bill grows with the size of the suite and the number of runs in CI. Grader output also varies between calls, so a rubric that passes on one run may fail on the next near the threshold. Ask your team to confirm how the grader model is configured, whether its temperature and output format are fixed, and what happens when a grader call errors or times out. Grader prompts are part of your test code and need their own review, since a vague rubric will pass anything well formatted. The design of judge prompts, judge selection and bias checks is covered on the sibling pages on LLM-as-a-judge evals and writing llm-rubric assertions.

The decision path from test case to assertion type

The path starts with a single test case and asks one question first: can code check the expected output? If yes, the case goes to a deterministic assertion such as equals, regex or is-json. If no, the next question is whether a reference answer exists, which routes the case to a factuality-style check, or whether only a rubric applies, which routes it to a model grader. The final stage runs cheap checks first and sends only outputs that pass them to the graders, so you spend model calls where they add signal. Check that every case has one clear route.

Routing each test case to a deterministic check, a reference check or a model grader.

How to order cheap checks before model graders in one test

This sequence builds one test case that runs objective checks first, so malformed or rule-breaking outputs are caught without paying for a model grader. The model grader is reserved for the one quality dimension that no deterministic check can cover.

  1. Inventory the quality dimensions for the test

    The team owning the LLM feature lists every property a passing output must have, such as required fields, a fixed format, a mandatory disclaimer, a business rule or a tone requirement. Each item is tagged as objective (can be checked with a string, pattern, JSON parse or code) or judgment-based (needs a reader to decide). The output is a short table with one row per dimension and one column for the check type, which becomes the input for every later step.

  2. Add format and content checks first

    Write the objective checks for the format and content rows, using assertions such as equals, contains, not-contains, regex and is-json in the promptfoo config. Run a handful of known good and known bad outputs through the test to confirm each assertion passes and fails for the right reason. Confirm the exact assertion names, options and evaluation order against the current promptfoo documentation before relying on them, since these details can change between releases.

  3. Encode business rules in a JavaScript assertion

    Add a JavaScript assertion for rules that combine several conditions, such as a refund amount that must match a value in the context, a date that must fall in an allowed window or a field that must be consistent with another field. Keep the function pure and return a boolean or a score with a reason, so a failure is readable in the report. Test the function on a few hand-built outputs before wiring it into the suite, because a buggy rule will produce false failures that look like model regressions.

  4. Confirm deterministic failures skip the model call

    Build one test case whose output violates a format check, then run the eval with verbose logging or the provider call count visible in the output. Check that the model-graded assertion is not invoked for that case, and that the case is reported as failed on the first objective assertion. If the grader still runs, review the assertion ordering and the threshold settings in the config, and confirm the behavior in the documentation for the version you have installed.

  5. Add one model-graded assertion for the remaining dimension

    Take the judgment-based row left over from the inventory and write one llm-rubric or similar model-graded assertion for it. The rubric should describe only that dimension, such as whether the answer is helpful and grounded in the supplied text, so the grader does not re-check format or rules already covered. Choose the grader model separately from the model under test, and record which grader and version was used so results remain comparable across runs.

  6. Verify the mixed set on labeled cases

    Create a small labeled set with outputs that should pass, fail on format, fail on a business rule and fail on quality only. Run the full test and compare the verdicts with the labels, noting which assertion produced each result. Any case that fails on the wrong assertion points to a gap in ordering or rubric scope, and the set should be kept in the repository so it runs again after prompt or model changes.

  7. Record the cost profile and review it

    Count how many cases reach the model grader in a full run, and compare that with the total number of cases before the objective checks were added. Ask the team to confirm that grader calls drop for cases with known format or rule failures, and note that grader cost recurs on every run and scales with the case count and grader model. Keep the ordering and thresholds documented in the config, so a reviewer can see why each assertion sits where it does.

Setting up a first mixed eval on your own machine

The fastest way to learn how assertion types behave is to run them against your own prompts on your own machine. Install promptfoo with Node.js 22.22.0 or newer, which is the requirement for the npm release supplied with this page, and confirm the exact version you install before you start, since the current release may differ from the one referenced here. Then write one small promptfooconfig.yaml with two or three prompts, four or five test cases, and at least one assertion of each kind: a deterministic check such as equals, contains or is-json, and a single llm-rubric assertion for the judgment you cannot express as a pattern. Keep the first run small so that any failure is easy to trace back to its cause.

Run the eval from the command line in the directory that holds the config. Because promptfoo's documentation states that evals run locally and talk directly to the model provider, the requests leave your machine only for the model calls you configured, and your API keys stay in your local environment. Confirm which provider and model each prompt targets in the config before running, since a mistyped model identifier is a common reason a first run produces misleading results.

The real check comes after the run. Open the results view and deliberately look for failures: each assertion should fail on at least one output you expect it to reject. Verify that is-json fails on prose wrapped around a JSON object, that equals fails on a near-miss string, and that the rubric grader fails an answer that is well formatted but wrong. If an assertion never fails, it is not yet testing anything, so tighten its value or add a case that should break it before you trust the suite.

Security and data handling for graders that see production outputs

A model grader reads whatever the eval hands it: model outputs, source documents and sometimes customer records. The cards below cover where that data travels, who receives it, where credentials live and how a grader can be manipulated, so the team can decide what a grader may see before the first run.

Where the grader runs

promptfoo runs on the machine or CI runner that starts the eval, but a model grader is a call to a model provider. Each grading request carries the output under test, the rubric and any inlined source text to that provider. Map which of your assertions send production text, and decide whether that text can leave your environment at all. Test with sanitized data first.

promptfoo introduction

Which provider receives the data

The grader provider is a separate party with its own retention, training and logging terms, and it may differ from the target model you are testing. Ask the provider for its data retention period, whether prompts are used for training and where processing happens. Record the grader provider in the eval config so reviewers can see which third party saw each test.

Credentials in the config

Grader and target providers need API keys, which often end up in promptfooconfig.yaml or CI variables. Keep keys in your secrets manager or CI secret store, reference them through environment variables, and keep config files out of version control when they hold literal values. Use a separate, least-privilege key for graders so a leaked eval key does not expose production model access.

Injected instructions in graded output

The model under test may produce text that tries to steer the judge, such as an instruction to return a passing score. A grader that reads that text can be pushed toward a false pass. Keep rubrics in a fixed system prompt, wrap the output as quoted data, and add deterministic checks that a model-written sentence cannot override. Test the judge with adversarial outputs before trusting it.

Network access in JavaScript assertions

A JavaScript assertion runs code you wrote, and nothing stops that code from making outbound network calls unless you prevent it. Review every custom assertion before it enters a shared suite, and keep those files free of HTTP clients, DNS lookups and shell calls unless a reviewer has approved them. Run evals in a network-restricted runner where the suite does not need outbound access.

Review grader provider terms

Before a grader sees customer data, read the provider's current terms for data use, retention, subprocessors and regional processing, and check that they match your contracts and sector rules. Ask your privacy and compliance leads to sign off on the grader and the data classes it may receive. Recheck terms when you change grader models, since each provider has its own agreement.

Questions teams ask before choosing assertion types

Are deterministic assertions enough on their own?

Often they are enough for structured outputs, but not for open-ended answers. Deterministic assertions such as equals, contains, regex, is-json and JavaScript functions check things you can define exactly: a format, a required field, a forbidden string, a value in a range. They cannot judge whether a free-text answer is accurate, complete or on-tone. If your application returns classifications, extracted fields or tool calls, start with objective checks and add a grader only for the properties they cannot reach. Most suites mix both, with objective checks as the first gate.

What drives the cost of model-graded assertions?

Cost comes from the grader model's per-token price, multiplied by how many graded calls the suite makes. The main drivers are the number of test cases, the number of model-graded assertions on each case, the length of the output and any source material you inline for the grader, and retries after failures or rate limits. Each cost is variable and recurs on every run, so it grows with CI frequency. Objective assertions add almost nothing. To control spend, keep graded assertions to the cases that need them, inline only the context the grader requires, and ask your provider for current grader pricing before you set run frequency.

How long does a first promptfoo eval suite take to build?

Duration depends on how many behaviors you must cover, how clean your sample data is, and how many people must agree on pass criteria. A suite that checks one output format is a small job. A suite spanning several prompts, models and graders takes longer, mostly in the test-case and acceptance-criteria work rather than in configuration. Ask for a written scope listing the applications, prompts, assertion types and number of cases before you agree a timeline. A fixed-scope engagement sets this out in writing before work starts, and a quote should follow directly from that scope.

What does the team need to provide for a suite?

You need to provide representative inputs and sample outputs, written acceptance criteria, and a named owner for each rubric. Sample outputs from production or staging show what good and bad answers look like, which is what makes assertions testable. Acceptance criteria define what counts as a regression, such as a minimum pass rate or a required field. Rubric owners are the people who can say whether a grader's verdict is correct, and they should review failures regularly. Also confirm access to the target application, the grader model credentials and a place to run the suite, such as a CI runner.

Can an internal engineer build this without outside help?

Yes, if someone on the team has time, basic Node.js familiarity and authority to define pass criteria. promptfoo is MIT-licensed and the Community edition includes all LLM evaluation features, so the tooling cost is low. The harder part is the judgment work: deciding what to test, writing rubrics that reject wrong answers and agreeing thresholds across product, security and engineering. Teams often bring in a partner for that scoping and for CI wiring, then maintain the suite internally. Check which skills your team has before deciding, and treat ongoing maintenance as a recurring task with a named owner.

How do you reduce flakiness in model-graded tests?

Start by moving every check that can be deterministic out of the grader, because objective assertions produce the same result on every run. For graded assertions, pin the grader model version where your provider allows it, keep rubrics narrow and specific, and set thresholds instead of demanding perfect scores. Review a sample of grader verdicts against human judgment, since a grader can drift or favor certain phrasing. Also check that prompts and test data are version-controlled, so a failure can be traced to a change in the app rather than in the suite. Use caching and retry settings deliberately, and confirm current options in the promptfoo documentation.

When should a model grader replace an objective check?

Use a model grader when correctness depends on meaning rather than form. If the answer must match a reference fact, stay on topic, avoid unsupported claims or follow a tone rule, an objective check cannot tell you that. Before adding one, ask whether a regex, a JSON schema check or a JavaScript function could catch the same failure. If it could, use that, because it is cheaper and stable. Where a grader is needed, pair it with objective gates so that obviously broken outputs fail before any grader call is made, which keeps both cost and noise down.

How DeployOpen scopes and delivers promptfoo eval suites

DeployOpen starts from the assertion decision for each output your application produces, then builds a promptfoo suite that uses objective checks wherever they are enough and model graders only where they are needed. Every suite is scoped in writing before work begins, so the grading choices, costs and handover are agreed up front.

How we scope

  • Inventory each output type and mark which ones an objective check such as equals, regex or is-json can verify.
  • Identify the outputs that need a model grader and agree the rubric owner and the judge model in writing.
  • Agree the fixed scope, deliverables and timeline in writing before any suite work starts.

How we build

  • Write the deterministic assertions first, then add model-graded assertions only for properties that need judgment.
  • Keep judge prompts and rubrics in version control so grading changes are reviewed like code.
  • Test the suite against known good and known bad outputs to confirm each assertion fails when it should.

How we hand over

  • Document which assertion type covers each test, why it was chosen, and which provider runs each grader.
  • Walk your engineers through running the suite locally and in your pipeline, including how to read failures.
  • Deliver the configuration files, test data and runbook in your own repository and infrastructure.

How we support

  • Offer ongoing support, upgrades and continuous testing as a retainer after handover.
  • Review grader drift and assertion pass rates when you change models, prompts or providers.
  • Confirm with your team which support boundaries, response expectations and access arrangements apply before signing.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.