fix(agents): resolve string annotations in tools - #2687
Merged
kevinmessiaen merged 4 commits intoAug 5, 2026
Conversation
Under `from __future__ import annotations` the RunContext parameter was never detected, so it leaked into the model-facing schema and context injection silently stopped.
Closed
davidberenstein1957
had a problem deploying
to
ci
August 3, 2026 09:39 — with
GitHub Actions
Failure
Assert on the tool's returned string, not just the RunContext side effect, so the test pins the pre-fix "swallowed validation error" failure mode instead of only its symptom. Add coverage for the TYPE_CHECKING-only-import behavior change called out in the PR description (PydanticUserError -> NameError, both at decoration time). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
kevinmessiaen
approved these changes
Aug 5, 2026
kevinmessiaen
left a comment
Member
There was a problem hiding this comment.
Thanks for the fix @BILLKISHORE
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.
What
@toolbreaks in any module usingfrom __future__ import annotations(PEP 563), where every annotation reachesinspect.signatureas a string.Tools taking a user-defined type raise at decoration time:
create_modelreceives the string"Point"and tries to resolve it intool.py's namespace instead of the caller's.The quieter failure is
RunContext.Tool.from_callabledetects it withparam.annotation is RunContext, which is never true against the string"RunContext". Fordef needs_ctx(text: str, ctx: RunContext):Context injection stops,
ctxleaks into the model-facing schema as a required property, and the resulting validation error is swallowed by the defaultcatchhandler and returned to the model as an ordinary tool result.Fix
eval_str=Trueresolves annotations againstfn.__globals__, which is the defining module.One behaviour change worth flagging: a type imported only under
if TYPE_CHECKING:now fails withNameError: name 'Decimal' is not definedwhere it previously failed withPydanticUserError: 'price' is not fully defined. Both fail at decoration time, before and after, so nothing that used to work stops working. The message just points at the real cause.Testing
New
libs/giskard-agents/tests/test_tools_future_annotations.py, 4 tests covering RunContext detection, schema exclusion, injection, and a model-annotated parameter. All 4 fail before the change and pass after, on 3.13. I also checked directly thatinspect.signatureresolves these annotations the same way on 3.12, 3.13 and 3.14.make test-unit PACKAGE=giskard-agents: 121 passed, 2 skipped. Full suite across all packages: 1281 passed.ruff checkandbasedpyrightclean.xref: no open PR touches
tools/tool.py.Note: the lint job will be red here until #2686 lands. Unrelated to this change.
Type of Change
Disclosure: drafted with AI assistance (Claude Code). I reproduced both failure modes, confirmed the tests fail before the fix and pass after, and ran the checks myself before submitting.