{"record":{"id":"8d8effe34b9ff2ab","repo":"rohitg00/ai-engineering-from-scratch","slug":"tc-mode","errorCode":null,"errorMessage":"tc.mode","messagePattern":"tc\\.mode","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/13-tools-and-protocols/02-function-calling-deep-dive/code/main.py","lineNumber":113,"sourceCode":"            {\n                \"name\": tool.name,\n                \"description\": tool.description,\n                \"parameters\": _gemini_schema(tool.input_schema),\n            }\n        ]\n    }\n\n\ndef tool_choice_openai(tc: ToolChoice) -> Any:\n    if tc.mode == \"auto\":\n        return \"auto\"\n    if tc.mode == \"none\":\n        return \"none\"\n    if tc.mode == \"required\":\n        return \"required\"\n    if tc.mode == \"force\":\n        return {\"type\": \"function\", \"function\": {\"name\": tc.tool_name}}\n    raise ValueError(tc.mode)\n\n\ndef tool_choice_anthropic(tc: ToolChoice) -> dict:\n    if tc.mode == \"auto\":\n        return {\"type\": \"auto\"}\n    if tc.mode == \"none\":\n        return {\"type\": \"none\"}\n    if tc.mode == \"required\":\n        return {\"type\": \"any\"}\n    if tc.mode == \"force\":\n        return {\"type\": \"tool\", \"name\": tc.tool_name}\n    raise ValueError(tc.mode)\n\n\ndef tool_choice_gemini(tc: ToolChoice) -> dict:\n    mode_map = {\"auto\": \"AUTO\", \"none\": \"NONE\", \"required\": \"ANY\"}\n    if tc.mode in mode_map:\n        return {\"function_calling_config\": {\"mode\": mode_map[tc.mode]}}","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/13-tools-and-protocols/02-function-calling-deep-dive/code/main.py#L95-L131","documentation":"Sentinel fallback guard at the end of tool_choice_openai: tc.mode matched none of 'auto', 'none', 'required', or 'force', so the raw mode value is re-raised as the error text. The input at fault is ToolChoice.mode — typically a typo or a provider-specific spelling that was never normalized.","triggerScenarios":"Thrown at phases/13-tools-and-protocols/02-function-calling-deep-dive/code/main.py:113 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set tc.mode to one of 'auto', 'none', 'required', or 'force'","Validate ToolChoice.mode at construction time instead of at translation time","Map provider-specific mode spellings before calling tool_choice_openai"],"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"}