"""Original TrendsWhat synthetic output-contract lab. MIT license. No model calls or private data. Run: python3 run-output-validation.py results.json """ import datetime import json import math import re import sys from pathlib import Path cases = [ ('valid', '{"amount":12.5,"currency":"USD","date":"2026-09-15"}'), ('missing-field', '{"amount":12.5,"date":"2026-09-15"}'), ('numeric-string', '{"amount":"12.5","currency":"USD","date":"2026-09-15"}'), ('impossible-date', '{"amount":12.5,"currency":"USD","date":"2026-02-30"}'), ('negative-amount', '{"amount":-12.5,"currency":"USD","date":"2026-09-15"}'), ('unsupported-currency', '{"amount":12.5,"currency":"ZZZ","date":"2026-09-15"}'), ('extra-key', '{"amount":12.5,"currency":"USD","date":"2026-09-15","approved":true}'), ('fenced-json', '```json\n{"amount":12.5,"currency":"USD","date":"2026-09-15"}\n```'), ] results=[] for name,raw in cases: try: value=json.loads(raw) parsed=True except json.JSONDecodeError: value=None parsed=False shape=(parsed and isinstance(value,dict) and set(value)=={'amount','currency','date'} and type(value['amount']) in (int,float) and math.isfinite(value['amount']) and isinstance(value['currency'],str) and bool(re.fullmatch('[A-Z]{3}',value['currency'])) and isinstance(value['date'],str) and bool(re.fullmatch(r'\d{4}-\d{2}-\d{2}',value['date']))) errors=[] if shape: if value['amount']<=0: errors.append('amount must be positive for this fictional task') if value['currency'] not in {'USD','KRW'}: errors.append('currency is outside this fictional application allowlist') try: datetime.date.fromisoformat(value['date']) except ValueError: errors.append('date does not exist in the calendar') results.append(dict(case=name,input=raw,parsed=parsed,shape_valid=shape,semantic_valid=shape and not errors,semantic_errors=errors)) report=dict(executed_at=datetime.datetime.now(datetime.timezone.utc).isoformat(),scope='Eight synthetic records; fictional positive-amount entry contract; USD/KRW allowlist; no model benchmark.',cases=results,totals={key:sum(r[key] for r in results) for key in ['parsed','shape_valid','semantic_valid']}) Path(sys.argv[1] if len(sys.argv)>1 else 'results.json').write_text(json.dumps(report,indent=2)+'\n') print(json.dumps(report['totals']))