Testing JSON summary checks with Promptfoo Echo
Feed fixed responses to Promptfoo Echo to verify that schema errors and missing release facts fail the right checks in a local run.
An empty
breaking_changesarray fits my JSON schema. For Jekyll 4.4.0 it leaves out the Ruby minimum. I built one good response and two deliberate failures, then ran them through Promptfoo to see which assertion fired and what the shell returned.
I tested this with Promptfoo 0.126.0 and Node.js 22.23.3. Echo supplied fixed strings. I ran the actual Promptfoo CLI and opened its local viewer.
Give structure and release facts their own checks
In my OpenRouter JSON Schema example, I passed mock HTTP responses through the SDK to test the Python validation. This time the input is the Jekyll 4.4.0 release note, which raised the minimum Ruby version to 2.7. The shape permits an empty array because some releases have no breaking changes. For this release, the empty array would hide a compatibility requirement. Jekyll 4.4.0 release notes
My live Ollama comparison produced an output that put the Ruby requirement in a different field. Here I control the output so I can change one thing at a time and check that the intended assertion fails. The two experiments use the same schema and JavaScript files. Promptfoo JSON evaluation
Define the schema and the expectations for one release
In summary.schema.json, I require the version, feature list, and breaking changes list. Both lists contain strings. The schema also rejects unexpected keys. It permits empty lists so an application can use the same contract for a release without any compatibility changes.
1
2
3
4
5
6
7
8
9
10
{
"type": "object",
"required": ["version", "features", "breaking_changes"],
"additionalProperties": false,
"properties": {
"version": { "type": "string" },
"features": { "type": "array", "items": { "type": "string" } },
"breaking_changes": { "type": "array", "items": { "type": "string" } }
}
}
Promptfoo calls the exported function in release-facts.cjs with (output, context). The function parses the output and checks the version and feature terms against context.vars.expected. This excerpt handles the breaking changes list. The Jekyll case sets breakingTerm to Ruby 2.7. Cases without that key require an empty list. result(failures) returns { pass, score, reason } with a reason based on the accumulated failures. JavaScript assertion return values
1
2
3
4
5
6
7
8
9
10
11
// release-facts.cjs — breaking changes check
const breaking = data?.breaking_changes
if (!Array.isArray(breaking)) {
failures.push('breaking_changes must be an array')
} else if (expected.breakingTerm) {
if (!breaking.join(' ').toLowerCase().includes(expected.breakingTerm.toLowerCase())) {
failures.push(`breaking_changes is missing "${expected.breakingTerm}"`)
}
} else if (breaking.length !== 0) {
failures.push('breaking_changes must be empty for this release')
}
This is a test for a particular phrase in a particular field. It would accept a string containing Ruby 2.7 even if the sentence got the direction of the version change wrong. For summaries that can express the same fact in several ways, I would check the wording cases against the release source before treating this rule as a quality measure.
Feed the checks known responses with Echo
Echo returns the rendered prompt, so I use {{fixture}} as the prompt and place each fixed response in tests[].vars.fixture. Each test also has a description. The good response contains the Liquid change, the three dependency names, and the Ruby requirement. I add debug: true to make the schema fail. In a separate case, I change just breaking_changes to [] to make the fact check fail. Echo provider
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# echo.yaml
prompts:
- label: Fixed JSON response
raw: '{{fixture}}'
providers:
- echo
defaultTest:
vars:
expected:
version: '4.4.0'
featureTerms: [Liquid, csv, base64, json]
breakingTerm: 'Ruby 2.7'
assert:
- type: is-json
value: file://summary.schema.json
metric: JSON schema
- type: javascript
value: file://release-facts.cjs
metric: Release facts
| Fixed response | JSON schema | Release facts |
|---|---|---|
| Known good | Pass | Pass |
Extra debug key | Fail | Pass |
Empty breaking_changes | Pass | Fail |
Figure 1. The local Promptfoo viewer shows the mock evaluation. The extra key and the missing Ruby requirement fail different assertions.
Check the exit status a CI step would receive
I ran all three fixtures and exported the result as JSON. The full run reported one pass, two failures, and zero errors. I then filtered to the case named Known good and got one pass, zero failures, and zero errors. Promptfoo CLI · Evaluation output formats
1
2
3
4
5
npx --no-install promptfoo eval -c echo.yaml \
--no-cache --no-table -o echo-results.json
npx --no-install promptfoo eval -c echo.yaml \
--filter-pattern '^Known good$' --no-cache --no-table --no-write
I put the eval command and a line that prints continued after eval in a local Bash script with set -e. The good case returned 0 and reached the print statement. The mixed run returned 100 and stopped before it. That reproduces the exit behavior a shell-based CI step would see. Keep the command’s exit status and the exported result. In each result cell, gradingResult.componentResults gives you the pass flag and reason for each assertion. The aggregate pass rate can stay the same while a different condition starts failing. This is the field I would inspect before changing the rule. CLI exit codes
Figure 2. Output from the local Bash run. Only the passing case reached the line after the eval command.
Keep the fixture run next to the live eval
- Keep data types and required keys in the schema. Put per-release facts in a separate assertion with a useful failure reason.
- Run fixed outputs to verify the test itself. Run fresh model responses against the same checks to evaluate a prompt change.
- Exercise both exit paths before adding the CLI to CI. Inspect the reported reason before changing a prompt or a test rule.