{"record":{"id":"5a1adde76e04354b","repo":"openai/openai-python","slug":"expected-json-schema-to-be-a-dictionary-path-p","errorCode":null,"errorMessage":"Expected {json_schema} to be a dictionary; path={path}","messagePattern":"Expected (.+?) to be a dictionary; path=(.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/openai/lib/_pydantic.py","lineNumber":37,"sourceCode":"    elif (not PYDANTIC_V1) and isinstance(model, pydantic.TypeAdapter):\n        schema = model.json_schema()\n    else:\n        raise TypeError(f\"Non BaseModel types are only supported with Pydantic v2 - {model}\")\n\n    return _ensure_strict_json_schema(schema, path=(), root=schema)\n\n\ndef _ensure_strict_json_schema(\n    json_schema: object,\n    *,\n    path: tuple[str, ...],\n    root: dict[str, object],\n) -> dict[str, Any]:\n    \"\"\"Mutates the given JSON schema to ensure it conforms to the `strict` standard\n    that the API expects.\n    \"\"\"\n    if not is_dict(json_schema):\n        raise TypeError(f\"Expected {json_schema} to be a dictionary; path={path}\")\n\n    defs = json_schema.get(\"$defs\")\n    if is_dict(defs):\n        for def_name, def_schema in defs.items():\n            _ensure_strict_json_schema(def_schema, path=(*path, \"$defs\", def_name), root=root)\n\n    definitions = json_schema.get(\"definitions\")\n    if is_dict(definitions):\n        for definition_name, definition_schema in definitions.items():\n            _ensure_strict_json_schema(definition_schema, path=(*path, \"definitions\", definition_name), root=root)\n\n    typ = json_schema.get(\"type\")\n    if typ == \"object\" and \"additionalProperties\" not in json_schema:\n        json_schema[\"additionalProperties\"] = False\n\n    # object types\n    # { 'type': 'object', 'properties': { 'a':  {...} } }\n    properties = json_schema.get(\"properties\")","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/lib/_pydantic.py#L19-L55","documentation":"_ensure_strict_json_schema recursively walks a JSON schema and mutates it to conform to the API's strict mode. Every node (including $defs entries) must be a JSON object/dict; encountering a non-dict node (e.g. a list or string where an object is expected) raises this TypeError with the path where it failed.","triggerScenarios":"A pydantic model whose generated JSON schema has a malformed node — typically caused by custom json_schema serializers, union weirdness, or hand-built TypeAdapters over non-schema types; also pydantic v1 generating differently-shaped schemas.","commonSituations":"Exotic pydantic field types or custom schema serializers; pydantic v1 environments; models using Any or untyped dict fields that emit non-object subschemas.","solutions":["Simplify the model: replace exotic/custom types with plain annotated types and regenerate","Upgrade to pydantic v2 latest, then retest the model's model_json_schema() output","Isolate the offending field by bisecting the model and inspecting model_json_schema() output at the failing path"],"exampleFix":"# before\nclass Output(BaseModel):\n    class Config:\n        json_schema_extra = lambda schema: schema.update(items=[])  # corrupts schema\n# after\nclass Output(BaseModel):\n    items: list[int]","handlingStrategy":"validation","validationCode":"schema = Output.model_json_schema()\nimport json; json.dumps(schema)  # smoke-test serializability\n# inspect nodes: every dict/def entry should be an object","typeGuard":null,"tryCatchPattern":"try:\n    strict = to_strict_json_schema(Output)\nexcept TypeError as e:\n    raise ValueError(f\"model {Output} produces a non-strict-compatible schema: {e}\") from e","preventionTips":["Keep output models simple and fully typed","Test schema generation in unit tests before deploying","Upgrade pydantic regularly"],"tags":["json-schema","pydantic","strict-mode","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}