rohitg00/ai-engineering-from-scratch · error · ValueError

schema for must be numeric

Error message

schema {keyword} for {location} must be numeric

What it means

Malformed-schema check: a numeric bound keyword (minimum, maximum, exclusiveMinimum, exclusiveMaximum) in the tool's input_schema holds a non-numeric value (string, bool, or null). The fault is in the schema definition, not in the argument being validated.

Solutions

  1. Use JSON numbers for bound keywords in the tool schema
  2. Validate tool schemas once at registration time, not on every call
  3. Lint schemas in tests with a shared helper that checks keyword types
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:139 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/0dfbc7498c81e1a2. Report an issue: GitHub.

Appendix: source

Thrown at certifications/claude/lessons/10-tool-use-and-agentic-loops/code/main.py:139

    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")
        maximum = _integer_bound(schema, "maxLength")
        if minimum is not None and len(value) < minimum:
            raise ValueError(f"invalid length for {location}: below minLength {minimum}")
        if maximum is not None and len(value) > maximum:
            raise ValueError(f"invalid length for {location}: above maxLength {maximum}")

    if isinstance(value, list):
        minimum = _integer_bound(schema, "minItems")
        maximum = _integer_bound(schema, "maxItems")
        if minimum is not None and len(value) < minimum:
            raise ValueError(f"invalid item count for {location}: below minItems {minimum}")
        if maximum is not None and len(value) > maximum:
            raise ValueError(f"invalid item count for {location}: above maxItems {maximum}")

View on GitHub (pinned to 39ea8a1c6d)