Skip to content

fix(core): use get_origin/get_args for robust args_schema annotation validation#1

Merged
ianalloway merged 1 commit intomasterfrom
devin/1771290734-robust-args-schema-validation
Feb 17, 2026
Merged

fix(core): use get_origin/get_args for robust args_schema annotation validation#1
ianalloway merged 1 commit intomasterfrom
devin/1771290734-robust-args-schema-validation

Conversation

@ianalloway
Copy link
Owner

Replaces the simple args_schema_type == BaseModel equality check in BaseTool.__init_subclass__ with a new _is_valid_args_schema_annotation() helper that uses get_origin()/get_args() to properly validate args_schema type annotations. This addresses the existing TODO on line 428.

The old check only caught the exact case args_schema: BaseModel. The new validator handles Type[BaseModel], Optional[Type[BaseModel]], Annotated[Type[BaseModel], ...], Union types, and bare BaseModelV1 — rejecting any bare BaseModel/subclass annotation that would cause runtime issues.

This is a behavioral change: the new code will now also reject args_schema: SomeCustomModel (bare subclass of BaseModel), not just args_schema: BaseModel exactly.

No tests were added. This PR was generated with AI assistance.

Human review checklist

  • Breaking change scope: The validation is now stricter — bare BaseModel subclasses are newly rejected. Verify this won't break existing downstream tools that accidentally use bare model annotations.
  • from __future__ import annotations impact: The file uses PEP 563 string annotations. Verify cls.__annotations__ behavior in __init_subclass__ for subclasses defined in modules with/without future annotations.
  • Test coverage: No tests added for _is_valid_args_schema_annotation(). Consider adding unit tests for the recursive validation logic.
  • Permissive default: The function returns True for unrecognized annotations (e.g., args_schema: str). Verify this is acceptable.

Link to Devin run: https://app.devin.ai/sessions/86b10eb8263049ef8e1b94ef22521f81
Requested by: @ianalloway

…validation

Resolves the TODO in BaseTool.__init_subclass__ by implementing
_is_valid_args_schema_annotation() which uses get_origin() and get_args()
to properly validate args_schema type annotations.

Previously, only a bare equality check against BaseModel was performed.
Now the validator correctly handles:
- Type[BaseModel] and type[BaseModel] (valid)
- Optional[Type[BaseModel]] (valid)
- Annotated[Type[BaseModel], ...] (valid)
- Union types containing valid annotations (valid)
- Bare BaseModel or BaseModelV1 subclasses (invalid - catches the error)
- NoneType (valid - means no schema)

Co-Authored-By: Ian Alloway <adapter_burners.1y@icloud.com>
@devin-ai-integration
Copy link

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@ianalloway ianalloway merged commit 6a29d48 into master Feb 17, 2026
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.

1 participant