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

invalid length for : below minLength

Error message

invalid length for {location}: below minLength {minimum}

What it means

String-length enforcement: the string at the named location is shorter than the schema's minLength allows; the message includes the required minimum. It fires while validating a tool argument against the locally implemented JSON-Schema subset.

Solutions

  1. Provide a longer string meeting minLength
  2. Lower minLength in the schema if the limit is too strict for valid input
  3. Generate example inputs from the schema in tests so lengths always comply
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

        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}")
        if "items" in schema:
            for index, item in enumerate(value):
                _validate_schema_value(item, schema["items"], f"{location}[{index}]")

    if isinstance(value, dict):
        properties = schema.get("properties", {})
        if not isinstance(properties, dict):
            raise ValueError(f"schema properties for {location} must be an object")

View on GitHub (pinned to 39ea8a1c6d)