rohitg00/ai-engineering-from-scratch · error · ValueError
invalid value for : not in enum
Error message
invalid value for {location}: not in enum What it means
JSON-Schema keyword check in _validate_schema_value: the tool argument at the named location is not one of the values listed in the schema's enum. This is the same rule the real API enforces on tool inputs, reproduced locally before the handler runs.
Solutions
- Send one of the allowed values listed in the tool's enum
- Extend the enum if a legitimate value is missing from the schema
- Validate against the schema before dispatch so the allowed choices can be shown to the caller
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:126 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26).
Data as JSON: /api/errors/7b66ef5d55abf276.
Report an issue: GitHub.
Appendix: source
Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:126
def _validate_schema_value(value: Any, schema: Any, location: str) -> None:
if not isinstance(schema, dict):
raise ValueError(f"schema for {location} must be an object")
declared_type = schema.get("type")
if declared_type is not None:
declared_types = declared_type if isinstance(declared_type, list) else [declared_type]
if not declared_types or not all(isinstance(item, str) for item in declared_types):
raise ValueError(f"schema type for {location} must be a string or non-empty string list")
if not any(_matches_json_type(value, item) for item in declared_types):
expected = " or ".join(declared_types)
raise ValueError(f"invalid type for {location}: expected {expected}")
if "enum" in schema:
choices = schema["enum"]
if not isinstance(choices, list) or not choices:
raise ValueError(f"schema enum for {location} must be a non-empty list")
if value not in choices:
raise ValueError(f"invalid value for {location}: not in enum")
if isinstance(value, (int, float)) and not isinstance(value, bool):
for keyword, comparison, message in (
("minimum", lambda current, bound: current >= bound, "below minimum"),
("maximum", lambda current, bound: current <= bound, "above maximum"),
("exclusiveMinimum", lambda current, bound: current > bound, "at or below exclusive minimum"),
("exclusiveMaximum", lambda current, bound: current < bound, "at or above exclusive maximum"),
):
if keyword not in schema:
continue
bound = schema[keyword]
if not isinstance(bound, (int, float)) or isinstance(bound, bool):
raise ValueError(f"schema {keyword} for {location} must be numeric")
if not comparison(value, bound):
raise ValueError(f"invalid value for {location}: {message} {bound}")
if isinstance(value, str):
minimum = _integer_bound(schema, "minLength")View on GitHub (pinned to 39ea8a1c6d)