mlflow/mlflow · warning · ValueError
Invalid data for {pydantic_class.__name__}: {e}
Error message
Invalid data for {pydantic_class.__name__}: {e} What it means
validate_pydantic attempts to construct pydantic_class from the data dict (or re-validate a BaseModel via model_dump). Any construction/validation failure is re-raised as ValueError naming the model class, which the server surfaces as a 400 error.
Source
Thrown at mlflow/genai/agent_server/validator.py:26
ResponsesAgentResponse,
ResponsesAgentStreamEvent,
)
class BaseAgentValidator:
"""Base validator class with common validation methods"""
def validate_pydantic(self, pydantic_class: type[BaseModel], data: Any) -> None:
"""Generic pydantic validator that throws an error if the data is invalid"""
if isinstance(data, pydantic_class):
return
try:
if isinstance(data, BaseModel):
pydantic_class(**data.model_dump())
return
pydantic_class(**data)
except Exception as e:
raise ValueError(f"Invalid data for {pydantic_class.__name__}: {e}")
def validate_dataclass(self, dataclass_class: Any, data: Any) -> None:
"""Generic dataclass validator that throws an error if the data is invalid"""
if isinstance(data, dataclass_class):
return
try:
dataclass_class(**data)
except Exception as e:
raise ValueError(f"Invalid data for {dataclass_class.__name__}: {e}")
def validate_and_convert_request(self, data: dict[str, Any]) -> dict[str, Any]:
return data
def validate_and_convert_result(self, result: Any, stream: bool = False) -> dict[str, Any]:
# Base implementation doesn't use stream parameter, but subclasses do
if isinstance(result, BaseModel):
return result.model_dump(exclude_none=True)
elif is_dataclass(result):View on GitHub (pinned to 6a27f2decc)
Solutions
- Read the wrapped pydantic error (included in the message) and fix the offending field
- Validate your payload locally with pydantic_class(**data) before calling the endpoint
- Regenerate payloads from the current SDK/model schema rather than hand-building dicts
Example fix
# before
validate_pydantic(ChatAgentRequest, {"messages": "hi"}) # messages must be a list
# after
validate_pydantic(ChatAgentRequest, {"messages": [{"role": "user", "content": "hi"}]}) Defensive patterns
Strategy: validation
Validate before calling
try:
PydanticClass(**payload)
except Exception as e:
raise ValueError(f"payload invalid before send: {e}") Type guard
from pydantic import BaseModel
from typing import Type, Any
def matches_model(model: Type[BaseModel], data: Any) -> bool:
if not isinstance(data, dict):
return False
try:
model(**data)
return True
except Exception:
return False Try / catch
try:
result = client.predict(payload)
except ValueError as e:
if "Invalid data for" in str(e):
logger.error("Fix fields per pydantic error: %s", e) Prevention
- Construct payloads via the pydantic model itself
- Keep model schemas in a shared package across client/server
- Run payload round-trip tests on schema changes
When it happens
Trigger: Passing a dict missing required pydantic fields, with wrong field types, or a BaseModel instance whose dumped fields no longer satisfy the target class.
Common situations: Client sending payloads that don't match the agent's input/output pydantic models; schema drift between SDK versions; nested objects typed incorrectly.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- {validation_error_msg} Pydantic validation error: {e}
- The input list is empty
- The dict format is invalid for this route type. Ensure the s
- One or more lists in the returned prediction response are em
- Invalid data for {dataclass_class.__name__}: {e}
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/f30ad60b08322294.
Report an issue: GitHub.