pydantic/pydantic · error · ValueError

model_config['json_schema_extra']={json_schema_extra} should

Error message

model_config['json_schema_extra']={json_schema_extra} should be a dict, callable, or None

What it means

Error "model_config['json_schema_extra']={json_schema_extra} should be a dict, callable, or None" thrown in pydantic/pydantic.

Source

Thrown at pydantic/json_schema.py:1741

                )
            if root_json_schema_extra:
                json_schema_extra = root_json_schema_extra

        if isinstance(json_schema_extra, (staticmethod, classmethod)):
            # In older versions of python, this is necessary to ensure staticmethod/classmethods are callable
            json_schema_extra = json_schema_extra.__get__(cls)

        if isinstance(json_schema_extra, dict):
            json_schema.update(json_schema_extra)
        elif callable(json_schema_extra):
            if len(_typing_extra.signature_no_eval(json_schema_extra).parameters) > 1:
                json_schema_extra = cast(Callable[[JsonDict, type[Any]], None], json_schema_extra)
                json_schema_extra(json_schema, cls)
            else:
                json_schema_extra = cast(Callable[[JsonDict], None], json_schema_extra)
                json_schema_extra(json_schema)
        elif json_schema_extra is not None:
            raise ValueError(
                f"model_config['json_schema_extra']={json_schema_extra} should be a dict, callable, or None"
            )

        if hasattr(cls, '__deprecated__'):
            json_schema['deprecated'] = True

    def resolve_ref_schema(self, json_schema: JsonSchemaValue) -> JsonSchemaValue:
        """Resolve a JsonSchemaValue to the non-ref schema if it is a $ref schema.

        Args:
            json_schema: The schema to resolve.

        Returns:
            The resolved schema.

        Raises:
            RuntimeError: If the schema reference can't be found in definitions.
        """

View on GitHub (pinned to 2e5f0e2b42)

When it happens

Trigger: Thrown at pydantic/json_schema.py:1741 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pydantic/pydantic@2e5f0e2b42 (2026-08-04). Data as JSON: /data/errors/d1beab2766d1e329.json. Report an issue: GitHub.