{"record":{"id":"a063f7f3aa54d598","repo":"rohitg00/ai-engineering-from-scratch","slug":"uncertainfallback-is-required","errorCode":null,"errorMessage":"uncertainFallback is required","messagePattern":"uncertainFallback is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/02-model-selection-and-token-economics/code/main.py","lineNumber":63,"sourceCode":"        if not str(case.get(\"routingSignal\", \"\")).strip():\n            errors.append(f\"cases[{index}] needs an observable routingSignal\")\n        if case.get(\"riskClass\") == \"consequential\" and case.get(\"humanReview\") is not True:\n            errors.append(f\"cases[{index}] consequential work must have humanReview\")\n    comparison = benchmark.get(\"routingComparison\")\n    routed = sum(case.get(\"estimatedCostUnits\", 0) for case in cases if isinstance(case, dict))\n    if not isinstance(comparison, dict) or comparison.get(\"routedCostUnits\") != routed:\n        errors.append(\"routedCostUnits must equal the case total\")\n    elif comparison.get(\"allCapableCostUnits\", 0) <= routed:\n        errors.append(\"allCapableCostUnits must exceed routedCostUnits\")\n    if not isinstance(comparison, dict) or not str(comparison.get(\"uncertainFallback\", \"\")).strip():\n        errors.append(\"uncertainFallback is required\")\n    return errors\n\n\ndef summarize(benchmark: dict[str, Any]) -> dict[str, Any]:\n    errors = validate_benchmark(benchmark)\n    if errors:\n        raise ValueError(\"; \".join(errors))\n    lanes = Counter(case[\"chosenModel\"] for case in benchmark[\"cases\"])\n    comparison = benchmark[\"routingComparison\"]\n    return {\n        \"caseCount\": len(benchmark[\"cases\"]),\n        \"lanes\": dict(sorted(lanes.items())),\n        \"costSavedUnits\": comparison[\"allCapableCostUnits\"] - comparison[\"routedCostUnits\"],\n        \"humanReviewCases\": sum(case[\"humanReview\"] for case in benchmark[\"cases\"]),\n    }\n\n\ndef validate_mode_trials(experiment: dict[str, Any]) -> list[str]:\n    errors: list[str] = []\n    if experiment.get(\"measurementStatus\") != \"illustrative-not-live-provider-runs\":\n        errors.append(\"mode trials must identify illustrative measurements\")\n    if not str(experiment.get(\"settingSemantics\", \"\")).strip():\n        errors.append(\"mode trials must explain normalized setting labels\")\n    verified_on = experiment.get(\"verifiedOn\")\n    if not _iso_date(verified_on):","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/02-model-selection-and-token-economics/code/main.py#L45-L81","documentation":"Benchmark-contract check in summarize: a routing benchmark must declare an uncertainFallback entry, and the loaded JSON is missing it or leaves it blank. The fallback route is what the analysis uses when the routing signal is ambiguous, so scoring cannot proceed without it.","triggerScenarios":"Thrown at certifications/claude/lessons/02-model-selection-and-token-economics/code/main.py:63 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add an uncertainFallback object with its model, cost, and latency to the benchmark JSON","Re-run with the benchmark file shipped in the lesson instead of a trimmed copy","Validate required top-level keys right after load and list all missing fields in one error"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}