{"record":{"id":"71b2eaa4719ddd19","repo":"BerriAI/litellm","slug":"defer-loading-must-be-a-boolean","errorCode":null,"errorMessage":"defer_loading must be a boolean","messagePattern":"defer_loading must be a boolean","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/anthropic/chat/transformation.py","lineNumber":802,"sourceCode":"                    returned_tool[\"cache_control\"] = _cache_control\n                elif _cache_control_function is not None and isinstance(_cache_control_function, dict):\n                    returned_tool[\"cache_control\"] = ChatCompletionCachedContent(**_cache_control_function)\n\n        ## check if defer_loading is set in the tool\n        _defer_loading: Final = tool.get(\"defer_loading\", None)\n        _defer_loading_function: Final = tool.get(\"function\", {}).get(\"defer_loading\", None)\n        if returned_tool is not None:\n            # Only set defer_loading on tools that support it (not tool search tools or computer tools)\n            tool_type = returned_tool.get(\"type\", \"\")\n            if tool_type not in (\n                \"tool_search_tool_regex_20251119\",\n                \"tool_search_tool_bm25_20251119\",\n                \"computer_20241022\",\n                \"computer_20250124\",\n            ):\n                if _defer_loading is not None:\n                    if not isinstance(_defer_loading, bool):\n                        raise ValueError(\"defer_loading must be a boolean\")\n                    returned_tool[\"defer_loading\"] = _defer_loading\n                elif _defer_loading_function is not None:\n                    if not isinstance(_defer_loading_function, bool):\n                        raise ValueError(\"defer_loading must be a boolean\")\n                    returned_tool[\"defer_loading\"] = _defer_loading_function\n\n        ## check if allowed_callers is set in the tool\n        _allowed_callers: Final = tool.get(\"allowed_callers\", None)\n        _allowed_callers_function: Final = tool.get(\"function\", {}).get(\"allowed_callers\", None)\n        if returned_tool is not None:\n            # Only set allowed_callers on tools that support it (not tool search tools or computer tools)\n            tool_type = returned_tool.get(\"type\", \"\")\n            if tool_type not in (\n                \"tool_search_tool_regex_20251119\",\n                \"tool_search_tool_bm25_20251119\",\n                \"computer_20241022\",\n                \"computer_20250124\",\n            ):","sourceCodeStart":784,"sourceCodeEnd":820,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/anthropic/chat/transformation.py#L784-L820","documentation":"While mapping optional tool attributes, LiteLLM found a top-level 'defer_loading' key on a tool that supports it (i.e. not a tool-search or computer tool) but its value is not a Python bool. The value is type-checked strictly, so strings like 'true' or 1/0 are rejected with this ValueError.","triggerScenarios":"Passing {'type': 'custom', ..., 'defer_loading': 'true'} or defer_loading: 1 in a tool dict; values loaded from YAML/JSON config where booleans arrive as strings ('true'/'false') or ints.","commonSituations":"YAML configs parsed without bool coercion (only literal true/false become bool; quoted 'true' stays a string); JSON produced by another service that serializes booleans as 0/1; env-var-driven flags injected as strings.","solutions":["Use a real boolean: defer_loading: true (unquoted) in YAML, or true in JSON.","If the value comes from config/env, coerce before building the tool: bool parsing like value in ('true', '1', True).","Note defer_loading may also live under 'function' (that path is checked only when the top-level key is absent)."],"exampleFix":"# before (YAML/config)\n\"defer_loading\": \"true\"  # string -> ValueError\n\n# after\n\"defer_loading\": True    # actual boolean","handlingStrategy":"validation","validationCode":"for t in tools:\n    if \"defer_loading\" in t and not isinstance(t[\"defer_loading\"], bool):\n        t[\"defer_loading\"] = str(t[\"defer_loading\"]).lower() in (\"true\", \"1\")","typeGuard":"def defer_loading_ok(tool) -> bool:\n    v = tool.get(\"defer_loading\")\n    return v is None or isinstance(v, bool)","tryCatchPattern":null,"preventionTips":["In YAML write defer_loading: true unquoted.","Run a coercion pass over config-loaded tool dicts before calling LiteLLM."],"tags":["anthropic","tools","defer-loading","type-validation","config"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}