You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deserializing an invalid component raises TypeError: ValueError: 'error' required in context instead of the validation message #269
When a component fails a custom validator while being deserialized with AgentSpecDeserializer.from_dict / from_json / from_yaml (or Component.from_dict and friends), the deserializer does not report the validation error. It crashes with TypeError: ValueError: 'error' required in context while rebuilding the ValidationError, and the actual message (which node is unreachable, which input is not in the prompt, which client configuration is not allowed, ...) is lost.
This affects every error raised by a @model_validator_with_error_accumulation validator, i.e. the value_error entries, which is how most Agent Spec components report configuration problems.
Reproduction
frompyagentspec.flows.edgesimportControlFlowEdgefrompyagentspec.flows.flowimportFlowfrompyagentspec.flows.nodesimportEndNode, StartNodefrompyagentspec.serializationimportAgentSpecDeserializerstart, end=StartNode(id="start", name="start"), EndNode(id="end", name="end")
flow=Flow(
id="flow", name="flow", start_node=start, nodes=[start, end],
control_flow_connections=[ControlFlowEdge(id="edge", name="edge", from_node=start, to_node=end)],
)
config=flow.to_dict()
# add a second end node that no control flow edge reaches: rejected by a Flow validatorunreachable= {**config["$referenced_components"]["end"], "id": "unreachable_end", "name": "unreachable_end"}
config["nodes"].append(unreachable)
AgentSpecDeserializer().from_dict(config)
File ".../pyagentspec/serialization/pydanticdeserializationplugin.py", line 66, in deserialize
raise ValidationError.from_exception_data(
title=component.__class__.__name__,
line_errors=line_errors,
)
TypeError: ValueError: 'error' required in context
Building the same invalid Flow directly in Python reports the problem correctly:
pydantic_core._pydantic_core.ValidationError: 1 validation error for Flow
Value error, Found an end node without any incoming control flow edge, which is not permitted (node is 'unreachable_end'). Please check the control flow edges.
Expected behavior
Deserialization raises a ValidationError carrying the original error type and message, as direct construction does.
Root cause
PydanticComponentDeserializationPlugin.deserialize (pyagentspec/src/pyagentspec/serialization/pydanticdeserializationplugin.py) collects the validation errors of the component and rebuilds a ValidationError with InitErrorDetails(type=e.type, loc=e.loc, input=()). pydantic cannot render error types such as value_error from the type alone: they need the ctx of the original error (the error key), which is not passed, so ValidationError.from_exception_data raises the TypeError. The partial-construction path (from_partial_dict) is not affected because it returns the collected errors instead of rebuilding them.
Environment
pyagentspec main (26.4.0.dev0, 5d1fa9b), pydantic 2.12.5, Python 3.13
Activity
fix(serialization): preserve validation error messages when deseriali…
fix(serialization): preserve validation error messages when deseriali…