{"record":{"id":"7305faa1586c5fa0","repo":"rohitg00/ai-engineering-from-scratch","slug":"schema-enum-for-location-must-be-a-non-empty-lis","errorCode":null,"errorMessage":"schema enum for {location} must be a non-empty list","messagePattern":"schema enum for (.+?) must be a non-empty list","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py","lineNumber":124,"sourceCode":"\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:\n        declared_types = declared_type if isinstance(declared_type, list) else [declared_type]\n        if not declared_types or not all(isinstance(item, str) for item in declared_types):\n            raise ValueError(f\"schema type for {location} must be a string or non-empty string list\")\n        if not any(_matches_json_type(value, item) for item in declared_types):\n            expected = \" or \".join(declared_types)\n            raise ValueError(f\"invalid type for {location}: expected {expected}\")\n\n    if \"enum\" in schema:\n        choices = schema[\"enum\"]\n        if not isinstance(choices, list) or not choices:\n            raise ValueError(f\"schema enum for {location} must be a non-empty list\")\n        if value not in choices:\n            raise ValueError(f\"invalid value for {location}: not in enum\")\n\n    if isinstance(value, (int, float)) and not isinstance(value, bool):\n        for keyword, comparison, message in (\n            (\"minimum\", lambda current, bound: current >= bound, \"below minimum\"),\n            (\"maximum\", lambda current, bound: current <= bound, \"above maximum\"),\n            (\"exclusiveMinimum\", lambda current, bound: current > bound, \"at or below exclusive minimum\"),\n            (\"exclusiveMaximum\", lambda current, bound: current < bound, \"at or above exclusive maximum\"),\n        ):\n            if keyword not in schema:\n                continue\n            bound = schema[keyword]\n            if not isinstance(bound, (int, float)) or isinstance(bound, bool):\n                raise ValueError(f\"schema {keyword} for {location} must be numeric\")\n            if not comparison(value, bound):\n                raise ValueError(f\"invalid value for {location}: {message} {bound}\")\n","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py#L106-L142","documentation":"_validate_schema_value raises ValueError(f'schema enum for {location} must be a non-empty list') when a (sub)schema contains an \"enum\" keyword whose value is not a list or is an empty list. Like the other schema-shape errors this reports a malformed schema, not bad data: an enum constraint with no choices is meaningless, so the validator refuses it at schema-check time.","triggerScenarios":"Schemas like {\"type\": \"string\", \"enum\": \"abc\"} (string instead of list), {\"enum\": []} (empty), or an enum built from a config/API source list that came back empty. Hit at any properties/items location once the type check passes.","commonSituations":"Generating enums dynamically from a listing that returns nothing; typos like enum: \"low|medium|high\"; YAML configs where a single-item enum collapses to a scalar.","solutions":["Write the enum as a non-empty JSON array of allowed values: {\"enum\": [\"low\", \"medium\", \"high\"]}.","When generating enums in code, fail loudly or fall back to a default if the source list is empty.","In YAML configs, always use list syntax even for one item: enum: [\"yes\"].","Read {location} in the message to locate the offending subschema."],"exampleFix":"# before\n{\"type\": \"string\", \"enum\": \"low|medium|high\"}\n# ValueError: schema enum for $.priority must be a non-empty list\n\n# after\n{\"type\": \"string\", \"enum\": [\"low\", \"medium\", \"high\"]}","handlingStrategy":"validation","validationCode":"def enum_keyword_ok(schema: dict) -> bool:\n    return \"enum\" not in schema or (isinstance(schema[\"enum\"], list) and len(schema[\"enum\"]) > 0)","typeGuard":"def is_valid_enum(choices) -> bool:\n    return isinstance(choices, list) and len(choices) > 0","tryCatchPattern":"try:\n    validate_tool_input(value, schema)\nexcept ValueError as exc:\n    if \"schema enum\" in str(exc):\n        raise SchemaError(f\"fix the schema: {exc}\") from exc  # schema bug, not data bug\n    raise","preventionTips":["Always author enums as non-empty JSON arrays, even for a single value.","Fail loudly when dynamic enum sources (config, API listings) return empty lists.","In YAML, use explicit list syntax: enum: [\"a\", \"b\"]."],"tags":["python","json-schema","enum","validation"],"backgroundTag":"malformed-json-schema","analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}