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

invalid item count for

Error message

invalid item count for {location}: below minItems {minimum}

What it means

Array-size enforcement: the list at the named location has fewer items than the schema's minItems requires; the required minimum is included in the message. It fires during local validation of tool input against the schema subset.

Solutions

  1. Include at least minItems entries in the argument list
  2. Adjust minItems if single-item input is valid
  3. Validate array arity in shared fixtures so tests never trip the bound accidentally
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

            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")
        required = schema.get("required", [])
        if not isinstance(required, list) or not all(isinstance(name, str) for name in required):
            raise ValueError(f"schema required for {location} must be a string list")
        missing = [name for name in required if name not in value]
        if missing:
            raise ValueError(f"missing required fields: {', '.join(missing)}")
        unexpected = set(value) - set(properties)
        if unexpected and schema.get("additionalProperties") is False:

View on GitHub (pinned to 39ea8a1c6d)