← All Examples Example 04 / 12 Deterministic Format & Negative-Constraint Compliance
Prompt-First Example 04 · Evaluations · VerifyTask · Zero Judge Cost

Deterministic Format &
Negative Constraints

Test exact word counts, fence-free raw JSON, forbidden letters/words, and Markdown table conversion using pure TypeScript verify() functions — zero judge tokens.

File: examples/evals/instruction.ts Recreate: pnpm tsx examples/evals/instruction.ts Packages: @umwelten/evaluation @umwelten/pi
01 — The Prompt You Give Pi
“Write a zero-judge instruction-following EvalSuite in @umwelten/evaluation at temperature 0.0 with deterministic VerifyTasks: (1) an ocean sentence of EXACTLY 12 words, (2) raw JSON matching schema constraints with zero markdown code fences, (3) a 2-line sunset description banning 'beautiful', 'sky', 'orange', and '!', and (4) CSV-to-Markdown table conversion.”
Paste directly into pi or your coding agent with @umwelten/* installed. 4 min walkthrough
02 — The Example That Gets Built

Live workspace source: examples/evals/instruction.ts

Read directly from disk at site-build time — byte-for-byte identical to the typechecked script in this repo.

TypeScript examples/evals/instruction.ts
pnpm tsx examples/evals/instruction.ts
1#!/usr/bin/env node
2/**
3 * Instruction Following Eval — Deterministic scoring, zero LLM judge calls.
4 *
5 * Usage:
6 *   pnpm tsx examples/evals/instruction.ts              # instant deterministic mock
7 *   pnpm tsx examples/evals/instruction.ts --live       # live cloud + local models
8 */
9
10import "@umwelten/pi";
11import { EvalSuite } from "@umwelten/evaluation";
12import { FAST_MODEL_ROSTER, QUICK_FAST_MODELS } from "../_shared/fast-models.js";
13import { setupExampleRuntime } from "../_shared/mock-runtime.js";
14
15const MODELS = [
16  ...QUICK_FAST_MODELS,
17  FAST_MODEL_ROSTER.find((m) => m.name === "inkling-2-mini:latest"),
18].filter((m): m is NonNullable<typeof m> => Boolean(m));
19
20setupExampleRuntime(FAST_MODEL_ROSTER);
21
22const suite = new EvalSuite({
23  name: "instruction-eval",
24  systemPrompt:
25    "Follow the given instructions with exact format compliance. Output ONLY what is requested — no extra prose or markdown fences.",
26  temperature: 0.0,
27  models: MODELS,
28  allModels: FAST_MODEL_ROSTER,
29  tasks: [
30    {
31      id: "word-count",
32      name: "12-Word Ocean",
33      prompt:
34        "Write a sentence about the ocean that contains EXACTLY 12 words. Just the sentence, nothing else.",
35      maxScore: 5,
36      verify: (r) => {
37        const words = r
38          .trim()
39          .replace(/^["']|["']$/g, "")
40          .split(/\s+/)
41          .filter(Boolean);
42        const diff = Math.abs(words.length - 12);
43        if (diff === 0) return { score: 5, details: `${words.length} words ✓` };
44        if (diff <= 1) return { score: 3, details: `${words.length} words (off by ${diff})` };
45        return { score: 0, details: `${words.length} words (wanted 12)` };
46      },
47    },
48    {
49      id: "json-output",
50      name: "Raw JSON",
51      prompt:
52        'Output a JSON object: {"name": string, "age": number 25-35, "skills": array of 3 strings, "active": true}. No markdown fences, no explanation.',
53      maxScore: 5,
54      verify: (r) => {
55        let s = 0;
56        const fails: string[] = [];
57        const clean = r
58          .trim()
59          .replace(/^```json?\n?/, "")
60          .replace(/\n?```$/, "")
61          .trim();
62        try {
63          const obj = JSON.parse(clean) as Record<string, unknown>;
64          if (typeof obj.name === "string" && obj.name.length > 0) s++;
65          else fails.push("name");
66          if (typeof obj.age === "number" && obj.age >= 25 && obj.age <= 35) s++;
67          else fails.push("age");
68          if (Array.isArray(obj.skills) && obj.skills.length === 3) s++;
69          else fails.push("skills");
70          if (obj.active === true) s++;
71          else fails.push("active");
72          if (!r.includes("```")) s++;
73          else fails.push("fences");
74        } catch {
75          return { score: 0, details: "Invalid JSON" };
76        }
77        return { score: s, details: fails.length ? `Failed: ${fails.join(", ")}` : "Perfect" };
78      },
79    },
80    {
81      id: "negative-constraints",
82      name: "Constraints",
83      prompt:
84        'Write 2 sentences about a sunset, each on its own line. Do NOT use: "beautiful", "sky", "orange". No exclamation marks.',
85      maxScore: 5,
86      verify: (r) => {
87        let s = 0;
88        const fails: string[] = [];
89        const lo = r.toLowerCase();
90        if (!lo.includes("beautiful")) s++;
91        else fails.push('"beautiful"');
92        if (!lo.includes("sky")) s++;
93        else fails.push('"sky"');
94        if (!lo.includes("orange")) s++;
95        else fails.push('"orange"');
96        if (!r.includes("!")) s++;
97        else fails.push("!");
98        const lines = r
99          .trim()
100          .split("\n")
101          .filter((l) => l.trim());
102        if (lines.length === 2) s++;
103        else fails.push(`${lines.length} lines`);
104        return { score: s, details: fails.length ? `Failed: ${fails.join(", ")}` : "All constraints met" };
105      },
106    },
107    {
108      id: "markdown-table",
109      name: "MD Table",
110      prompt:
111        "Convert to a markdown table (Name, Age, Role columns):\nAlice, 28, Engineer\nBob, 34, Designer\nCharlie, 22, Student\nOutput ONLY the table.",
112      maxScore: 5,
113      verify: (r) => {
114        const lines = r
115          .trim()
116          .split("\n")
117          .filter((l) => l.trim());
118        let s = 0;
119        const fails: string[] = [];
120        if (lines.length >= 5) s++;
121        else fails.push(`${lines.length} lines`);
122        if (lines[0] && /Name/i.test(lines[0]) && /Age/i.test(lines[0])) s++;
123        else fails.push("header");
124        if (lines[1] && /[-|]+/.test(lines[1])) s++;
125        else fails.push("separator");
126        const hasData =
127          lines.some((l) => /Alice/i.test(l) && /28/.test(l)) &&
128          lines.some((l) => /Bob/i.test(l) && /34/.test(l));
129        if (hasData) s++;
130        else fails.push("data");
131        if (lines.every((l) => l.includes("|"))) s++;
132        else fails.push("pipes");
133        return { score: s, details: fails.length ? `Failed: ${fails.join(", ")}` : "Perfect table" };
134      },
135    },
136  ],
137});
138
139await suite.run();
03 — Captured Execution Telemetry

Captured stdout from running pnpm tsx examples/evals/instruction.ts

Captured Run Output pnpm tsx examples/evals/instruction.ts
🧪 Mode: MOCK (@earendil-works/pi-ai fauxProvider) — pass --live to hit real APIs & local GPUs

🧪 instruction-eval
══════════════════════════════════════════════════════════════════════
Tasks:   4 (12-Word Ocean, Raw JSON, Constraints, MD Table)
Models:  6
Max:     20 per model
Run:     #001
══════════════════════════════════════════════════════════════════════

📝 12-Word Ocean
  ✅ openrouter:openai/gpt-6-luna
  ✅ anthropic:claude-haiku-5-5
  ✅ google:gemini-4-hydrogen
  ✅ ollama:gemma4:26b
  ✅ openrouter:z-ai/glm-5.3-flash
  ✅ ollama:inkling-2-mini:latest
  ✅ google:gemini-4-hydrogen → 5/5 12 words ✓
  ✅ anthropic:claude-haiku-5-5 → 5/5 12 words ✓
  ✅ openrouter:openai/gpt-6-luna → 5/5 12 words ✓
  ✅ openrouter:z-ai/glm-5.3-flash → 5/5 12 words ✓
  ⚠️ ollama:gemma4:26b → 3/5 13 words (off by 1)
  ✅ ollama:inkling-2-mini:latest → 5/5 12 words ✓

📝 Raw JSON
  ✅ google:gemini-4-hydrogen
  ✅ anthropic:claude-haiku-5-5
  ✅ openrouter:z-ai/glm-5.3-flash
  ✅ openrouter:openai/gpt-6-luna
  ✅ ollama:gemma4:26b
  ✅ ollama:inkling-2-mini:latest
  ✅ google:gemini-4-hydrogen → 5/5 Perfect
  ✅ anthropic:claude-haiku-5-5 → 5/5 Perfect
  ✅ openrouter:openai/gpt-6-luna → 5/5 Perfect
  ✅ openrouter:z-ai/glm-5.3-flash → 5/5 Perfect
  ✅ ollama:gemma4:26b → 5/5 Perfect
  ✅ ollama:inkling-2-mini:latest → 5/5 Perfect

📝 Constraints
  ✅ google:gemini-4-hydrogen
  ✅ anthropic:claude-haiku-5-5
  ✅ openrouter:z-ai/glm-5.3-flash
  ✅ openrouter:openai/gpt-6-luna
  ✅ ollama:gemma4:26b
  ✅ ollama:inkling-2-mini:latest
  ✅ google:gemini-4-hydrogen → 5/5 All constraints met
  ✅ anthropic:claude-haiku-5-5 → 5/5 All constraints met
  ✅ openrouter:openai/gpt-6-luna → 5/5 All constraints met
  ✅ openrouter:z-ai/glm-5.3-flash → 5/5 All constraints met
  ✅ ollama:gemma4:26b → 5/5 All constraints met
  ✅ ollama:inkling-2-mini:latest → 5/5 All constraints met

📝 MD Table
  ✅ google:gemini-4-hydrogen
  ✅ anthropic:claude-haiku-5-5
  ✅ ollama:gemma4:26b
  ✅ openrouter:z-ai/glm-5.3-flash
  ✅ openrouter:openai/gpt-6-luna
  ✅ ollama:inkling-2-mini:latest
  ✅ google:gemini-4-hydrogen → 5/5 Perfect table
  ✅ anthropic:claude-haiku-5-5 → 5/5 Perfect table
  ✅ openrouter:openai/gpt-6-luna → 5/5 Perfect table
  ✅ openrouter:z-ai/glm-5.3-flash → 5/5 Perfect table
  ✅ ollama:gemma4:26b → 5/5 Perfect table
  ✅ ollama:inkling-2-mini:latest → 5/5 Perfect table


🏁 INSTRUCTION-EVAL — FINAL RANKINGS
══════════════════════════════════════════════════════════════════════════════════════════════════════════════
Model                                         Score        12-Word   Raw JSON  Constrai  MD Table  Cost       Time    
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
🥇 ollama:inkling-2-mini:latest                20/20 (100%) 5/5       5/5       5/5       5/5       $0.0000    0.0s    
🥇 openrouter:z-ai/glm-5.3-flash               20/20 (100%) 5/5       5/5       5/5       5/5       $0.0000    0.0s    
🥇 anthropic:claude-haiku-5-5                  20/20 (100%) 5/5       5/5       5/5       5/5       $0.0001    0.0s    
🥇 openrouter:openai/gpt-6-luna                20/20 (100%) 5/5       5/5       5/5       5/5       $0.0001    0.0s    
🥇 google:gemini-4-hydrogen                    20/20 (100%) 5/5       5/5       5/5       5/5       $0.0011    0.0s    
🥇 ollama:gemma4:26b                           18/20 (90%)  3/5       5/5       5/5       5/5       $0.0000    0.0s    

💰 Total cost: $0.0013
04 — How & Why This Extends Pi

Architectural notes

Whenever constraints are syntactic — word counts, valid JSON without ```json wrappers, acrostics, or lipograms — deterministic VerifyTask functions execute in microseconds with zero judge variance.