fix(core): use get_origin/get_args for robust args_schema annotation validation#1
Merged
ianalloway merged 1 commit intomasterfrom Feb 17, 2026
Conversation
…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 EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the simple
args_schema_type == BaseModelequality check inBaseTool.__init_subclass__with a new_is_valid_args_schema_annotation()helper that usesget_origin()/get_args()to properly validateargs_schematype annotations. This addresses the existing TODO on line 428.The old check only caught the exact case
args_schema: BaseModel. The new validator handlesType[BaseModel],Optional[Type[BaseModel]],Annotated[Type[BaseModel], ...],Uniontypes, and bareBaseModelV1— 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 justargs_schema: BaseModelexactly.No tests were added. This PR was generated with AI assistance.
Human review checklist
from __future__ import annotationsimpact: The file uses PEP 563 string annotations. Verifycls.__annotations__behavior in__init_subclass__for subclasses defined in modules with/without future annotations._is_valid_args_schema_annotation(). Consider adding unit tests for the recursive validation logic.Truefor unrecognized annotations (e.g.,args_schema: str). Verify this is acceptable.Link to Devin run: https://app.devin.ai/sessions/86b10eb8263049ef8e1b94ef22521f81
Requested by: @ianalloway