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

unsupported schema keywords

Error message

unsupported schema keywords: {sorted(unknown)}

What it means

Closed-vocabulary check in validate_schema_shape: the top-level schema uses keywords outside ALLOWED_KEYWORDS (the deliberately small supported subset of JSON Schema). Unfamiliar keywords cannot be enforced by the mini validator, so they are rejected instead of silently ignored.

Solutions

  1. Remove the unsupported keywords listed in the error
  2. Re-express the constraint with supported keywords (e.g. allOf compositions are out of scope by design)
  3. Extend ALLOWED_KEYWORDS and the _walk validator together if a keyword is genuinely needed
  4. Keep tool schemas minimal; the subset is intentionally educational
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phases/19-capstone-projects/21-tool-registry-schema-validation/code/main.py:117 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/77c30d81256df564. Report an issue: GitHub.

Appendix: source

Thrown at phases/19-capstone-projects/21-tool-registry-schema-validation/code/main.py:117

    def names(self) -> list[str]:
        return list(self._order)

    def validate(self, name: str, args: Any) -> Ok | list[ValidationError]:
        rec = self.get(name)
        errors: list[ValidationError] = []
        _walk(rec.schema, args, "", errors)
        if errors:
            return errors
        return Ok()


def validate_schema_shape(schema: dict) -> None:
    """Reject schemas using keywords outside the supported subset."""
    if not isinstance(schema, dict):
        raise ValueError("schema must be a dict")
    unknown = set(schema.keys()) - ALLOWED_KEYWORDS
    if unknown:
        raise ValueError(f"unsupported schema keywords: {sorted(unknown)}")
    t = schema.get("type")
    if t is not None and t not in PRIMITIVE_TYPE_MAP:
        raise ValueError(f"unsupported type: {t!r}")
    enum_vals = schema.get("enum")
    if enum_vals is not None and not isinstance(enum_vals, list):
        raise ValueError("enum must be a list")
    min_len = schema.get("minLength")
    if min_len is not None:
        if isinstance(min_len, bool) or not isinstance(min_len, int) or min_len < 0:
            raise ValueError("minLength must be a non-negative integer")
    max_len = schema.get("maxLength")
    if max_len is not None:
        if isinstance(max_len, bool) or not isinstance(max_len, int) or max_len < 0:
            raise ValueError("maxLength must be a non-negative integer")
    if min_len is not None and max_len is not None and min_len > max_len:
        raise ValueError("minLength cannot be greater than maxLength")
    pattern = schema.get("pattern")
    if pattern is not None and not isinstance(pattern, str):

View on GitHub (pinned to 39ea8a1c6d)