{"record":{"id":"25388d6d6330a886","repo":"rohitg00/ai-engineering-from-scratch","slug":"minlength-must-be-a-non-negative-integer","errorCode":null,"errorMessage":"minLength must be a non-negative integer","messagePattern":"minLength must be a non-negative integer","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/21-tool-registry-schema-validation/code/main.py","lineNumber":127,"sourceCode":"\n\ndef validate_schema_shape(schema: dict) -> None:\n    \"\"\"Reject schemas using keywords outside the supported subset.\"\"\"\n    if not isinstance(schema, dict):\n        raise ValueError(\"schema must be a dict\")\n    unknown = set(schema.keys()) - ALLOWED_KEYWORDS\n    if unknown:\n        raise ValueError(f\"unsupported schema keywords: {sorted(unknown)}\")\n    t = schema.get(\"type\")\n    if t is not None and t not in PRIMITIVE_TYPE_MAP:\n        raise ValueError(f\"unsupported type: {t!r}\")\n    enum_vals = schema.get(\"enum\")\n    if enum_vals is not None and not isinstance(enum_vals, list):\n        raise ValueError(\"enum must be a list\")\n    min_len = schema.get(\"minLength\")\n    if min_len is not None:\n        if isinstance(min_len, bool) or not isinstance(min_len, int) or min_len < 0:\n            raise ValueError(\"minLength must be a non-negative integer\")\n    max_len = schema.get(\"maxLength\")\n    if max_len is not None:\n        if isinstance(max_len, bool) or not isinstance(max_len, int) or max_len < 0:\n            raise ValueError(\"maxLength must be a non-negative integer\")\n    if min_len is not None and max_len is not None and min_len > max_len:\n        raise ValueError(\"minLength cannot be greater than maxLength\")\n    pattern = schema.get(\"pattern\")\n    if pattern is not None and not isinstance(pattern, str):\n        raise ValueError(\"pattern must be a string\")\n    props = schema.get(\"properties\")\n    if props is not None:\n        if not isinstance(props, dict):\n            raise ValueError(\"properties must be a dict\")\n        for pname, psub in props.items():\n            if not isinstance(pname, str):\n                raise ValueError(\"property names must be strings\")\n            validate_schema_shape(psub)\n    items = schema.get(\"items\")","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/21-tool-registry-schema-validation/code/main.py#L109-L145","documentation":"Bounds check in validate_schema_shape for minLength: the keyword is present but its value is a bool, a non-integer, or a negative integer. The validator explicitly excludes booleans (bool subclasses int in Python), so minLength must be a plain non-negative int to be enforceable.","triggerScenarios":"Thrown at phases/19-capstone-projects/21-tool-registry-schema-validation/code/main.py:127 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set minLength to a non-negative integer literal","Watch for booleans leaking in from flag variables used as lengths","Coerce numeric config values to int at load time if they arrive as floats","Fix generators that compute minLength from possibly-negative expressions"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}