{"record":{"id":"a9656a1d81964c1c","repo":"rohitg00/ai-engineering-from-scratch","slug":"unsupported-schema-type-expected","errorCode":null,"errorMessage":"unsupported schema type: {expected}","messagePattern":"unsupported schema type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py","lineNumber":95,"sourceCode":"        \"execution\": execution,\n        \"procedure\": \"skill\" if needs.reusable_procedure else \"inline-instructions\",\n        \"execution_boundary\": boundary,\n        \"authorization_owner\": \"application-policy\",\n    }\n\n\ndef _matches_json_type(value: Any, expected: str) -> bool:\n    checks: dict[str, Callable[[Any], bool]] = {\n        \"null\": lambda item: item is None,\n        \"boolean\": lambda item: isinstance(item, bool),\n        \"integer\": lambda item: isinstance(item, int) and not isinstance(item, bool),\n        \"number\": lambda item: isinstance(item, (int, float)) and not isinstance(item, bool),\n        \"string\": lambda item: isinstance(item, str),\n        \"array\": lambda item: isinstance(item, list),\n        \"object\": lambda item: isinstance(item, dict),\n    }\n    if expected not in checks:\n        raise ValueError(f\"unsupported schema type: {expected}\")\n    return checks[expected](value)\n\n\ndef _integer_bound(schema: dict[str, Any], name: str) -> int | None:\n    if name not in schema:\n        return None\n    value = schema[name]\n    if not isinstance(value, int) or isinstance(value, bool) or value < 0:\n        raise ValueError(f\"schema {name} must be a non-negative integer\")\n    return value\n\n\ndef _validate_schema_value(value: Any, schema: Any, location: str) -> None:\n    if not isinstance(schema, dict):\n        raise ValueError(f\"schema for {location} must be an object\")\n\n    declared_type = schema.get(\"type\")\n    if declared_type is not None:","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py#L77-L113","documentation":"_matches_json_type raises ValueError(f'unsupported schema type: {expected}') when a schema's declared type string is not one of the supported JSON types (boolean, integer, number, string, array, object). This lesson-scoped mini-validator treats an unsupported type name ('null', 'int', 'str', 'any') as an authoring bug in the schema, not a data problem, and fails fast instead of silently passing.","triggerScenarios":"Validating a tool input_schema whose type is 'null', 'any', 'int', 'str', or misspelled; nesting such a subschema inside properties/items so _validate_schema_value recurses into _matches_json_type; passing a JSON-Schema draft using types this subset never implemented.","commonSituations":"Translating Python/TypeScript type names into schema types ('str' instead of 'string'); copying full JSON Schema specs that use 'null' or type arrays with unsupported members; hand-writing tool definitions.","solutions":["Replace the unsupported type with a supported one: 'string', 'integer', 'number', 'boolean', 'array', or 'object'.","If unions are needed, use a non-empty type list of supported names rather than unsupported type names.","Add a startup lint that walks the schema and rejects unknown type strings before any model call.","Keep test fixtures to the documented type vocabulary."],"exampleFix":"# before\n{\"type\": \"str\"}\n# ValueError: unsupported schema type: str\n\n# after\n{\"type\": \"string\"}","handlingStrategy":"validation","validationCode":"SUPPORTED_TYPES = {\"boolean\", \"integer\", \"number\", \"string\", \"array\", \"object\"}\ndef schema_types_ok(schema: dict) -> bool:\n    t = schema.get(\"type\")\n    types = t if isinstance(t, list) else [t]\n    return all(x in SUPPORTED_TYPES for x in types if x is not None)","typeGuard":"def is_supported_type_name(name: str) -> bool:\n    return name in {\"boolean\", \"integer\", \"number\", \"string\", \"array\", \"object\"}","tryCatchPattern":"try:\n    validate_tool_input(value, schema)\nexcept ValueError as exc:\n    if str(exc).startswith(\"unsupported schema type\"):\n        raise SchemaAuthoringError(str(exc)) from exc  # schema bug: fix schema, do not retry\n    raise","preventionTips":["Keep a whitelist of supported schema types in the authoring guide.","Lint schemas once at startup, not per validation call.","Avoid shorthand like 'str' or 'int' when hand-writing types."],"tags":["python","json-schema","validation","tool-definitions"],"backgroundTag":"unsupported-schema-type","analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}