Bare object schemas in tool parameters silently strip all keys (empty create_model + pydantic extra='ignore')
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 420
- Forks
- 60
- Avg merge
- 9h 30m
- Merged PRs (30d)
- 4
Description
Bug
pyagentspec/adapters/_utils.py::_build_type_from_schema converts an object schema with no declared properties — a bare {"type": "object"}, e.g. as items of an array parameter — into a pydantic model built by create_model() with zero fields. Pydantic v2 defaults to extra="ignore", so validating the LLM's arguments against that model silently drops every key: the tool receives {} (or [{}, ...] for arrays of objects) regardless of what the model actually sent, with no error anywhere.
Reproduction
from pyagentspec.adapters._utils import create_pydantic_model_from_properties
from pyagentspec.property import Property
model = create_pydantic_model_from_properties(
"ToolArgs",
[Property(title="components", json_schema={"type": "array", "items": {"type": "object"}})],
)
parsed = model(components=[{"id": "root", "component": "Card"}])
print(parsed.components) # [ComponentsItem()] — id/component are gone
Downstream symptom: any tool whose parameter schema uses opaque objects fails input-dependent logic with confusing errors, because the arguments arrive empty no matter what the model sends.
Expected
Per JSON Schema semantics, an object with no property constraints accepts any object. A bare object schema (no properties, additionalProperties not false) should map to a passthrough Dict[str, Any] rather than a stripping empty model. Schemas that declare properties/required or set additionalProperties: false should keep building typed models as today.
I have a fix with a regression test ready and will open a PR referencing this issue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pyagentspec/adapters/_utils.py at _build_type_from_schema and reproduce the issue with create_pydantic_model_from_properties using an array of bare objects. Check how empty create_model() results are validated, then add or review the mentioned regression test. Done means bare object values preserve arbitrary keys while schemas with properties or additionalProperties=false retain typed validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100