Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
feat(examples): re-derive the yes-or-no figure for /structured-output (#335)
svonava8333afa28f5b
diff --git a/examples/structured-output/README.md b/examples/structured-output/README.mdindex 2835b2cab..bbd34ef89 100644--- a/examples/structured-output/README.md+++ b/examples/structured-output/README.md@@ -10,11 +10,23 @@ Ten public records, each with its own JSON Schema, sent toNHTSA vehicle complaints, SEC officer appointment filings and GSA surplusvehicle listings.-The page publishes one figure:+The page's heading:-> All 10 documents came back as schema-valid JSON, 91 of 93 fields right+> All 21 yes-or-no fields came back right, and no document says true or false-`score.py` re-derives that figure from the recorded responses, offline.+and the line under its proof grid:++> 91 of 93 checked fields were right, and 11 of the 13 fields that pick from a+> fixed list were right++`score.py` re-derives every one of those from the recorded responses, offline.++A yes-or-no field is one the case schema declared `"type": "boolean"` or+`"type": ["boolean", "null"]`, and nothing wider, read from the schema the call+sent rather than from the value that came back. A union like+`["boolean", "string"]` is not a yes-or-no question and is not counted as one. Sixteen are plain booleans. Five admit null, and+two of those correctly came back null because the GSA listing gives no answer,+which still counts as a question the schema asked.Acceptance checks were written on 2026-09-15 from reading each source text,before that case's first model run, and are in `inputs/checks.json` with that@@ -61,15 +73,22 @@ documents scored: 10parsed as JSON: 10schema-valid: 10fields right: 91 of 93+ yes-or-no fields: 21 of 21+ picks from a list: 11 of 13+ everything else: 59 of 59+documents saying true or false: 0excluded from every total: 3 CPSC cases, listed with their reason in inputs/excluded.jsonfields the model got wrong:gsa-377053.condition: expected 'unknown', got 'repairable'nhtsa-11231274.components: expected ['AIR BAGS'], got ['FIRE RELATED']-Reproduced: all 10 documents schema-valid, 91 of 93 fields right.+Reproduced: all 21 yes-or-no fields right, no document says true or false, 91 of 93 checked fields right.```+Both fields the model got wrong are picks from a fixed list, which is why that+group scores 11 of 13 while the other two are perfect.+`score.py` needs nothing installed. Schema validation runs under the smallvalidator built into `score.py`, which covers the subset of JSON Schema thesecases use, and it prints `schema validator: built in`. If `jsonschema` happens@@ -108,6 +127,10 @@ byte of any request or response.- **Nothing about the two wrong fields being the only possible errors.** The93 checks cover the fields that could be read off each source text. Fieldsthe source does not state are schema-validated and not scored.+- **Nothing about why a yes-or-no field is right.** `score.py` establishes that+ the answer matches the check and that the words true and false appear in no+ source text. It cannot show the model reasoned rather than guessed, and with+ 21 binary answers a run of luck is not ruled out by this set.- **Nothing about reproducibility of a new run.** The figure is re-derived fromresponses recorded on 2026-09-15 against server version 0.7.3 and modelrevision `8bd714204e67a1c6c81f84b0dc486b6a6e96e943c42ff488f6b3cbf936e07955`.diff --git a/examples/structured-output/score.py b/examples/structured-output/score.pyindex ce18c433b..9ebaac2cd 100755--- a/examples/structured-output/score.py+++ b/examples/structured-output/score.py@@ -6,10 +6,20 @@Published on https://superlinked.com/structured-output:- All 10 documents came back as schema-valid JSON, 91 of 93 fields right+ All 21 yes-or-no fields came back right, and no document says true or false-This script re-derives 10, 10 and 91 of 93 offline, with no API key and no-inference spend. It exits nonzero if any of them fails to reproduce.+and, under the proof grid:++ 91 of 93 checked fields were right, and 11 of the 13 fields that pick from+ a fixed list were right++This script re-derives all of those offline, with no API key and no inference+spend. It exits nonzero if any of them fails to reproduce.++A yes-or-no field is one the case schema declared `"type": "boolean"` or+`"type": ["boolean", "null"]`. That is read from the schema the call actually+sent, not from the value that came back, so a field that correctly returned+null because its listing gives no answer still counts as a question asked.What it does:@@ -19,7 +29,9 @@ What it does:3. parses the assistant message of each recorded response as JSON;4. validates it against that case's JSON Schema from `data/inputs/cases.json`;5. applies the acceptance checks in `data/inputs/checks.json`, which were- written before each case's first run.+ written before each case's first run;+ 6. groups those checks by what the schema asked for, and searches each source+ text for the words true and false, which is the page's second claim.Schema validation runs under `jsonschema` when it is importable, and otherwiseunder the small validator in this file, which covers the subset these schemas@@ -31,6 +43,7 @@ from __future__ import annotationsimport argparseimport json+import reimport sysfrom collections.abc import Callablefrom pathlib import Path@@ -38,7 +51,46 @@ from typing import AnyHTTP_OK = 200-EXPECTED = {"cases": 10, "parsed": 10, "schema_valid": 10, "checks_passed": 91, "checks_total": 93}+EXPECTED = {+ "cases": 10,+ "parsed": 10,+ "schema_valid": 10,+ "checks_passed": 91,+ "checks_total": 93,+ "yes_no_passed": 21,+ "yes_no_total": 21,+ "enum_passed": 11,+ "enum_total": 13,+}++# The page heading says no document says true or false. Checked against the+# source texts here, not against that sentence.+LITERAL_BOOLEAN = re.compile(r"(?<![A-Za-z])(?:true|false)(?![A-Za-z])", re.IGNORECASE)+++# A yes-or-no field is one declared "boolean" or ["boolean", "null"], and+# nothing wider. Membership alone would also catch a union like+# ["boolean", "string"], which is not a yes-or-no question and would inflate the+# published count, so the whole declared set has to be one of these.+YES_NO_TYPES = frozenset({"boolean", "null"})+++def asked_for(spec: object) -> str:+ """What the schema declared a field to be: a yes-or-no question, a pick from+ a fixed list, or an ordinary value. Read from the schema that was sent."""+ if not isinstance(spec, dict):+ return "value"+ declared = spec.get("type")+ types = declared if isinstance(declared, list) else [declared]+ if "boolean" in types and set(types) <= YES_NO_TYPES:+ return "yes_no"+ items = spec.get("items")+ if isinstance(spec.get("enum"), list):+ return "enum"+ if isinstance(items, dict) and isinstance(items.get("enum"), list):+ return "enum"+ return "value"+JSON_TYPES = {"object": dict,@@ -169,9 +221,20 @@ def main() -> int:calls = scored_calls(load(data_dir / "calls.json"), lambda call: call["set"] == "page")name, module = validator()- totals = {"cases": 0, "parsed": 0, "schema_valid": 0, "checks_passed": 0, "checks_total": 0}+ totals = {+ "cases": 0,+ "parsed": 0,+ "schema_valid": 0,+ "checks_passed": 0,+ "checks_total": 0,+ "yes_no_passed": 0,+ "yes_no_total": 0,+ "enum_passed": 0,+ "enum_total": 0,+ }disagreements: list[str] = []wrong_fields: list[str] = []+ spelled_out: list[str] = []for call in calls:case_id = call["case"]@@ -200,11 +263,30 @@ def main() -> int:if recorded is not None and recorded != valid:disagreements.append(f"{case_id}: recorded valid={recorded}, recomputed valid={valid}")+ if LITERAL_BOOLEAN.search(cases[case_id]["text"]):+ spelled_out.append(case_id)+for check in checks[case_id]:totals["checks_total"] += 1- actual = value.get(check["field"]) if isinstance(value, dict) else None- if check_passes(check["op"], actual, check["expected"]):+ group = asked_for(schema.get("properties", {}).get(check["field"]))+ if group != "value":+ totals[f"{group}_total"] += 1+ # An absent field is not a returned null. `.get()` cannot tell them+ # apart, so a check expecting null would score a field the model+ # never returned as correct. Schema validation happens to catch that+ # today, because every case schema lists every property as required,+ # but that is a different check shielding this one rather than this+ # one working.+ present = isinstance(value, dict) and check["field"] in value+ actual = value.get(check["field"]) if present else None+ if present and check_passes(check["op"], actual, check["expected"]):totals["checks_passed"] += 1+ if group != "value":+ totals[f"{group}_passed"] += 1+ elif not present:+ wrong_fields.append(+ f"{case_id}.{check['field']}: expected {check['expected']!r}, field absent from the reply"+ )else:wrong_fields.append(f"{case_id}.{check['field']}: expected {check['expected']!r}, got {actual!r}")@@ -213,6 +295,13 @@ def main() -> int:print(f"parsed as JSON: {totals['parsed']}")print(f"schema-valid: {totals['schema_valid']}")print(f"fields right: {totals['checks_passed']} of {totals['checks_total']}")+ print(f" yes-or-no fields: {totals['yes_no_passed']} of {totals['yes_no_total']}")+ print(f" picks from a list: {totals['enum_passed']} of {totals['enum_total']}")+ print(+ f" everything else: {totals['checks_passed'] - totals['yes_no_passed'] - totals['enum_passed']}"+ f" of {totals['checks_total'] - totals['yes_no_total'] - totals['enum_total']}"+ )+ print(f"documents saying true or false: {len(spelled_out)}")print(f"excluded from every total: {len(excluded)} CPSC cases, listed with their reason in inputs/excluded.json")if wrong_fields:print("\nfields the model got wrong:")@@ -224,12 +313,17 @@ def main() -> int:]for line in disagreements:failures.append(f"validator disagreement, {line}")+ for case_id in spelled_out:+ failures.append(f"{case_id}: source text says true or false, so the page heading is wrong")if failures:print("\nFAILED to reproduce the published figure:", file=sys.stderr)for line in failures:print(f" {line}", file=sys.stderr)return 1- print("\nReproduced: all 10 documents schema-valid, 91 of 93 fields right.")+ print(+ f"\nReproduced: all {totals['yes_no_total']} yes-or-no fields right, no document says"+ f" true or false, {totals['checks_passed']} of {totals['checks_total']} checked fields right."+ )return 0