{"record":{"id":"27ed672ab6671cbb","repo":"shareAI-lab/learn-claude-code","slug":"goal-evaluator-impossible-must-be-boolean","errorCode":null,"errorMessage":"goal evaluator 'impossible' must be boolean","messagePattern":"goal evaluator 'impossible' must be boolean","errorType":"validation","errorClass":"GoalError","httpStatus":null,"severity":"error","filePath":"s17_goal_loop/code.py","lineNumber":192,"sourceCode":"        lines = stripped.splitlines()\n        if lines and lines[0].startswith(\"```\"):\n            lines = lines[1:]\n        if lines and lines[-1].strip() == \"```\":\n            lines = lines[:-1]\n        stripped = \"\\n\".join(lines).strip()\n    try:\n        value = json.loads(stripped)\n    except json.JSONDecodeError as error:\n        raise GoalError(\"goal evaluator returned invalid JSON\") from error\n    if not isinstance(value, dict):\n        raise GoalError(\"goal evaluator must return a JSON object\")\n    if not isinstance(value.get(\"ok\"), bool):\n        raise GoalError(\"goal evaluator response requires boolean 'ok'\")\n    if not isinstance(value.get(\"reason\"), str) or not value[\"reason\"].strip():\n        raise GoalError(\"goal evaluator response requires non-empty 'reason'\")\n    impossible = value.get(\"impossible\", False)\n    if not isinstance(impossible, bool):\n        raise GoalError(\"goal evaluator 'impossible' must be boolean\")\n    if value[\"ok\"] and impossible:\n        raise GoalError(\n            \"goal evaluator cannot return both ok and impossible\"\n        )\n    return {\n        \"ok\": value[\"ok\"],\n        \"reason\": value[\"reason\"].strip(),\n        \"impossible\": impossible,\n    }\n\n\nclass PromptGoalEvaluator:\n    \"\"\"A separate, tool-free model that judges the transcript.\"\"\"\n\n    def __init__(\n        self,\n        client: Any,\n        model: str,","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/shareAI-lab/learn-claude-code/blob/985456f4adea6f4df8fbad4112245dbd97444eae/s17_goal_loop/code.py#L174-L210","documentation":"The optional 'impossible' field defaults to false but, when present, must be a real boolean; GoalError(\"goal evaluator 'impossible' must be boolean\") guards against truthy stand-ins like 1, \"yes\", or null. impossible=true lets the loop terminate a goal that cannot be met, so its type must be exact.","triggerScenarios":"Evaluator JSON containing \"impossible\": \"no\" / 0 / null / [false] — present but not a bool.","commonSituations":"Models echoing free-text yes/no values; schemas allowing any type for the field; evaluators copying 'impossible' from prose annotations.","solutions":["Constrain 'impossible' in the evaluator schema to type:boolean (or omit the field entirely when false).","Show the allowed literal values in the evaluator prompt example.","Coerce in a custom evaluator: emit the field only as a JSON true/false literal."],"exampleFix":"# before: {\"ok\": false, \"reason\": \"blocked\", \"impossible\": \"no\"}\n\n# after: {\"ok\": false, \"reason\": \"blocked\", \"impossible\": false}","handlingStrategy":"type-guard","validationCode":"import json\nobj = json.loads(evaluator_text)\nimp = obj.get(\"impossible\", False)\nassert imp is True or imp is False, \"'impossible' must be a JSON boolean when present\"","typeGuard":"def impossible_is_bool_or_absent(value: object) -> bool:\n    if not isinstance(value, dict) or \"impossible\" not in value:\n        return True\n    return isinstance(value[\"impossible\"], bool)","tryCatchPattern":"try:\n    ev = _parse_json_object(text)\nexcept GoalError as e:\n    if \"'impossible' must be boolean\" in str(e):\n        obj = json.loads(text)\n        obj.pop(\"impossible\", None)  # drop malformed optional field, default false applies\n        ev = _parse_json_object(json.dumps(obj))\n    else:\n        raise","preventionTips":["Constrain 'impossible' to type:boolean in the evaluator schema, or tell the model to omit it when false.","Show the literal true/false values in the prompt example.","In custom evaluators, never emit yes/no strings for boolean fields."],"tags":["goal-loop","evaluator","json","type-validation","llm"],"backgroundTag":null,"analyzedSha":"985456f4adea6f4df8fbad4112245dbd97444eae","analyzedAt":"2026-08-14T22:02:26.028Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}