Skip to content

Tool ergonomics: dict schemas + keyword-only @tool name#74

Merged
eliasposen merged 5 commits intomainfrom
tool-ergonomics
May 8, 2026
Merged

Tool ergonomics: dict schemas + keyword-only @tool name#74
eliasposen merged 5 commits intomainfrom
tool-ergonomics

Conversation

@eliasposen
Copy link
Copy Markdown
Contributor

Summary

  • input_schema accepts JSON Schema dicts alongside Pydantic BaseModel classes. Dicts validated via jsonschema (Draft 2020-12); pydantic models still go through model_validate. Lets integrators wrap tools defined externally (MCP, OpenAPI, hand-written) without round-tripping through a synthetic pydantic model.
  • output_schema accepts JSON Schema dicts alongside Python types / typing constructs. TypeAdapter path preserved for rich Python output validation (datetime, BaseModel subclasses, etc.).
  • @tool decorator: name is now keyword-only; fn is the only positional argument. Enables @tool(input_schema=...) and @tool(output_schema=...) without forcing the user to also pass a name. Validators are compiled and cached at tool construction; malformed dict schemas raise jsonschema.SchemaError immediately.

Breaking change

@tool("custom_name") is no longer valid — use @tool(name="custom_name"). Migrated all in-repo call sites.

Test plan

  • Pre-existing tool/decorator/schema tests still pass
  • New tests for dict input/output schemas (validation success + failure paths)
  • New tests for malformed dict schemas raising at construction
  • New tests for explicit Pydantic model / Python type schemas overriding inference
  • New test for combined tool(fn, name=..., input_schema=..., output_schema=...) direct-call form
  • Async coverage for both schema forms
  • Updated error-path tests to match the new TypeError-based dispatch

🤖 Generated with Claude Code

@eliasposen eliasposen merged commit fed1f05 into main May 8, 2026
10 checks passed
@eliasposen eliasposen deleted the tool-ergonomics branch May 8, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants