Comparing JSON triage prompts with Promptfoo and Ollama
Run zero-cost local prompt evaluations with Promptfoo 0.126.0 and Ollama qwen2.5:1.5b, comparing format: json against JSON Schema structured outputs.
Pasting sample inputs into a chat window after every prompt edit hides regressions on older cases. Wiring Promptfoo to a local Ollama server lets you compare prompt versions and
format: jsonvs. JSON Schema outputs against the same dataset with zero API cost.
All numbers and outputs in this post come from live local
POST /api/chatruns on macOS (Apple Silicon) with Node.jsv22.23.3, Promptfoo0.126.0, and Ollama0.40.18runningqwen2.5:1.5b.
Why manual spot checks miss prompt regressions
Suppose your backend classifies incoming support tickets into { category, priority, requires_escalation, summary } JSON objects. You tighten the prompt to fix one misclassified billing ticket, and a week later you find out that production outage tickets started returning "Technical Support" instead of "bug" or flipping requires_escalation to false.
Iterating on early prompt drafts against hosted APIs adds latency, rate limits, and recurring token bills. Running Promptfoo against a local Ollama instance solves the feedback loop: you evaluate multiple prompt files and output constraints over the same test cases, then track schema compliance and domain accuracy as separate metrics.
Local Ollama runs need three guards that you usually skip with hosted APIs:
- Serial execution (
--max-concurrency 1): Promptfoo fans out requests in parallel by default. On a local machine, concurrent generation requests contend for memory bandwidth and skew latency numbers. - Immediate model unload (
keep_alive: 0): Ollama keeps loaded models in RAM/VRAM after a request finishes. Settingkeep_alive: 0in the provider config releases memory right after each evaluation run. - Fresh responses and stable sampling (
--no-cache,temperature: 0,seed: 42): Promptfoo caches responses on disk by default. Passing--no-cacheduring prompt comparisons guarantees fresh model output, while fixed temperature and seed reduce run-to-run variance.
Configuring the Ollama provider and evaluation matrix
Pin Promptfoo in a local project instead of installing it globally so every run uses the exact same CLI behavior.
1
2
npm init -y
npm install --save-exact promptfoo@0.126.0
Here are the two prompt variants under test. prompts/triage-v1.txt only lists the four field names, while prompts/triage-v2.txt defines the allowed enums and explicit escalation rules.
1
2
3
4
5
# prompts/triage-v1.txt
Classify this customer support ticket and respond in JSON with category, priority, requires_escalation, and summary.
Ticket:
{{ticket}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# prompts/triage-v2.txt
You are a support ticket triage classifier.
Return ONLY a single JSON object with these exact four keys and no extra keys:
- "category": one of "bug", "billing", "feature"
- "priority": one of "high", "medium", "low"
- "requires_escalation": boolean
- "summary": concise one-sentence summary (non-empty string)
Classification rules:
1. Production outages or HTTP 500 errors affecting orders -> category "bug", priority "high", requires_escalation true.
2. Duplicate charges, refunds, or invoice billing issues -> category "billing", priority "medium", requires_escalation false.
3. New feature or enhancement requests -> category "feature", priority "low", requires_escalation false.
Ticket:
{{ticket}}
Next, wire ollama:chat:qwen2.5:1.5b and three support tickets (a checkout HTTP 500 outage, a duplicate invoice charge, and a CSV export request) in promptfooconfig.yaml. If your Ollama daemon listens on a custom host or port, override it with OLLAMA_BASE_URL.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# promptfooconfig.yaml
description: "Local Ollama ticket triage prompt comparison (v1 vs v2)"
prompts:
- id: file://prompts/triage-v1.txt
label: "v1-basic"
- id: file://prompts/triage-v2.txt
label: "v2-strict"
providers:
- id: ollama:chat:qwen2.5:1.5b
label: "qwen2.5:1.5b (format=json)"
config:
temperature: 0
seed: 42
keep_alive: 0
format: json
defaultTest:
assert:
- type: is-json
value: file://triage.schema.json
metric: JSON schema
- type: javascript
value: file://triage-rules.cjs
metric: Triage rules
tests:
- description: "Checkout HTTP 500 outage"
vars:
ticket: "Checkout returns HTTP 500 for all KR cards since 14:10 KST. Orders are failing."
expectedCategory: "bug"
expectedPriority: "high"
expectedEscalation: true
- description: "Duplicate invoice charge"
vars:
ticket: "I was charged twice for invoice #INV-4092 and need a refund for the duplicate charge."
expectedCategory: "billing"
expectedPriority: "medium"
expectedEscalation: false
- description: "CSV export feature request"
vars:
ticket: "Could you add CSV export to the monthly usage dashboard?"
expectedCategory: "feature"
expectedPriority: "low"
expectedEscalation: false
Ollama’s config.format accepts two distinct modes. Passing the string json restricts decoding to syntactically valid JSON, but leaves key names and enum strings up to the model. Passing a JSON Schema object enables grammar-constrained structured outputs so the sampler only emits tokens that satisfy the required keys, types, and enum values.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# promptfooconfig-schema.yaml (providers excerpt)
providers:
- id: ollama:chat:qwen2.5:1.5b
label: "format: json"
config:
temperature: 0
seed: 42
keep_alive: 0
format: json
- id: ollama:chat:qwen2.5:1.5b
label: "format: json-schema"
config:
temperature: 0
seed: 42
keep_alive: 0
format:
type: object
additionalProperties: false
required: [category, priority, requires_escalation, summary]
properties:
category:
type: string
enum: ["bug", "billing", "feature"]
priority:
type: string
enum: ["high", "medium", "low"]
requires_escalation:
type: boolean
summary:
type: string
Separating JSON schema checks from triage rules
If you cram structural validation and business logic into one assertion, a failing cell doesn’t tell you whether the model broke the JSON contract or misclassified the ticket. Giving each check its own metric name in defaultTest.assert keeps the two failure modes separate.
First, is-json validates the raw response against triage.schema.json, enforcing additionalProperties: false, required fields, allowed enums, and a non-empty summary.
1
2
3
4
5
6
7
8
9
10
11
12
// triage.schema.json
{
"type": "object",
"additionalProperties": false,
"required": ["category", "priority", "requires_escalation", "summary"],
"properties": {
"category": { "type": "string", "enum": ["bug", "billing", "feature"] },
"priority": { "type": "string", "enum": ["high", "medium", "low"] },
"requires_escalation": { "type": "boolean" },
"summary": { "type": "string", "minLength": 5 }
}
}
Second, a javascript assertion parses the JSON and compares each field against context.vars. Returning { pass, score, reason } surfaces the exact field mismatches in both the web UI and the exported JSON report.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// triage-rules.cjs
module.exports = (output, context) => {
let data;
try {
data = JSON.parse(output);
} catch (err) {
return { pass: false, score: 0, reason: `Invalid JSON: ${err.message}` };
}
const vars = context.vars || {};
const failures = [];
if (data.category !== vars.expectedCategory) {
failures.push(`category=${JSON.stringify(data.category)} (expected ${JSON.stringify(vars.expectedCategory)})`);
}
const allowedPriorities = String(vars.expectedPriority || '').split('|').filter(Boolean);
if (allowedPriorities.length > 0 && !allowedPriorities.includes(data.priority)) {
failures.push(`priority=${JSON.stringify(data.priority)} (expected ${allowedPriorities.join(' or ')})`);
}
const expectedEsc = vars.expectedEscalation === true || vars.expectedEscalation === 'true';
if (data.requires_escalation !== expectedEsc) {
failures.push(`requires_escalation=${JSON.stringify(data.requires_escalation)} (expected ${expectedEsc})`);
}
if (failures.length > 0) {
return { pass: false, score: 0, reason: failures.join('; ') };
}
return {
pass: true,
score: 1,
reason: `Matched ${data.category}/${data.priority}/escalation=${data.requires_escalation}`,
};
};
Local run results: format: json vs. JSON Schema
Isolate the Promptfoo state directory and cache path so local experiments don’t touch ~/.promptfoo, then run the 6-cell comparison (v1-basic vs. v2-strict across 3 tickets):
1
2
3
4
5
6
7
PROMPTFOO_CONFIG_DIR=./.pf-config \
PROMPTFOO_CACHE_PATH=./.pf-cache \
npx promptfoo eval \
-c promptfooconfig.yaml \
--max-concurrency 1 \
--no-cache \
-o results-v1v2.json
All 6 calls to local qwen2.5:1.5b finished in 6.1 seconds with zero runtime errors, using 1,134 total tokens (366 for v1-basic, 768 for v2-strict). Individual cell latencyMs values ranged from 881 ms to 1,301 ms.
Opening the run with npx promptfoo view puts pass rates, token counts, average latency, and per-assertion failure reasons side by side:
Figure 1. Live local promptfoo view matrix comparing v1-basic and v2-strict on Ollama qwen2.5:1.5b (format: json).
Under format: json, v1-basic produced parseable JSON on every ticket, yet invented values outside the contract ("Technical Support", "Payment Error", "Feature Request", "High", "Normal"). Both JSON schema and Triage rules scored 0/3. Switching to v2-strict brought both metrics to 3/3.
That raised a follow-up question: if we keep v1-basic untouched and switch Ollama from format: json to a full JSON Schema object, does constrained decoding fix classification accuracy too? To test this, I ran promptfooconfig-schema.yaml across all 12 cells (2 format modes × 2 prompts × 3 tickets) with --max-concurrency 1 --no-cache.
Combination (qwen2.5:1.5b) | Checkout HTTP 500 outage | Duplicate invoice charge | CSV export feature request | JSON schema | Triage rules | Overall |
|---|---|---|---|---|---|---|
format: json + v1-basic | FAIL (Technical Support, High, false) | FAIL (Payment Error, High, false) | FAIL (Feature Request, Normal, false) | 0/3 | 0/3 | 0/3 |
format: json-schema + v1-basic | FAIL (billing, high, false) | FAIL (billing, high, false) | PASS (feature, low, false) | 3/3 | 1/3 | 1/3 |
format: json + v2-strict | PASS (bug, high, true) | PASS (billing, medium, false) | PASS (feature, low, false) | 3/3 | 3/3 | 3/3 |
format: json-schema + v2-strict | PASS (bug, high, true) | PASS (billing, medium, false) | PASS (feature, low, false) | 3/3 | 3/3 | 3/3 |
The split between the two metrics tells the whole story. Turning on format: json-schema lifted v1-basic’s JSON schema pass rate from 0/3 to 3/3 because constrained decoding blocked out-of-enum strings at generation time.
Even so, Triage rules only moved to 1/3. Without explicit triage rules in the prompt, the model labeled the HTTP 500 checkout outage as "billing" with requires_escalation: false, and bumped the duplicate invoice ticket to "high" instead of "medium". Schema-constrained decoding guarantees shape and allowed enum values, not domain judgment.
When you need to inspect failures from the command line or a script, results-v1v2.json and results-schema.json store latencyMs, the raw output, and gradingResult.componentResults for each cell. Here is the relevant slice from the failing format: json-schema + v1-basic outage cell:
1
2
3
4
5
6
7
8
9
10
11
12
{
"latencyMs": 977,
"output": "{\"category\":\"billing\",\"priority\":\"high\",\"requires_escalation\":false,\"summary\":\"...\"}",
"componentResults": [
{ "metric": "JSON schema", "pass": true, "reason": "Assertion passed" },
{
"metric": "Triage rules",
"pass": false,
"reason": "category=\"billing\" (expected \"bug\"); requires_escalation=false (expected true)"
}
]
}
Where local Ollama evaluation stops and pre-flight checks
Each layer in this setup covers a different failure mode:
| Mechanism | What it enforces | What it cannot enforce | Best fit |
|---|---|---|---|
format: json | Syntactically valid JSON | Required keys, enums, or classification rules | Early exploration while the schema is still changing |
format: <JSON Schema> | Keys, types, additionalProperties: false, enum values | Domain-specific routing or escalation policy | Production JSON pipelines that must never break parsing |
| Explicit prompt rules + assertions | Business classification rules and regression checks | Token-level decoding constraints | Comparing prompt revisions before release |
Local small-model runs (
qwen2.5:1.5b) are great for catching structural bugs, missing enum instructions, and coarse rule regressions at zero cost. Do not treat a 1.5B local pass as a substitute for evaluating the larger production model you actually ship: small models miss subtle edge cases, and outputs can still shift across Ollama model tags or quantization builds even withtemperature: 0and a fixedseed.
Before adopting this workflow in a team repository, check four items:
- Pin the exact model tag and sampling config: Keep the full tag (
qwen2.5:1.5b),temperature: 0,seed, andkeep_alive: 0insidepromptfooconfig.yaml. - Keep structural and domain metrics separate: Pair
is-jsonwith a dedicatedjavascriptassertion so schema breaks don’t mask business-rule regressions. - Standardize local flags: Default to
--max-concurrency 1 --no-cacheon laptops and workstations to avoid memory contention and stale cache hits. - Cross-check against your production model: Use local Ollama to tighten the prompt and assertions first, then run the same suite against your production target before deploying.