Skip to content

Validate tool results with return types#190

Open
msullivan wants to merge 1 commit into
mainfrom
tool-load
Open

Validate tool results with return types#190
msullivan wants to merge 1 commit into
mainfrom
tool-load

Conversation

@msullivan

Copy link
Copy Markdown
Contributor

We have to do a bunch of annoying type annotation magic to extract the
result type of aggregators from from type annotations.

A follow-up question here: should we use the aggregator to populate
model_input here, instead of in Agent? I will leave that to a second
PR.

The invocation for parsing tools with pydantic validation is:

ai.messages.Message.model_validate(
    data,
    context=ai.messages.tool_validate_context([weather]),
)

It is also now an argument to ai.agents.ui.ai_sdk.to_messages.

Happy to bikeshed about names.

We have to do a bunch of annoying type annotation magic to extract the
result type of aggregators from from type annotations.

A follow-up question here: should we use the aggregator to populate
model_input *here*, instead of in Agent? I will leave that to a second
PR.

The invocation for parsing tools with pydantic validation is:
```
ai.messages.Message.model_validate(
    data,
    context=ai.messages.tool_validate_context([weather]),
)
```

It is also now an argument to `ai.agents.ui.ai_sdk.to_messages`.

Happy to bikeshed about names.
@msullivan msullivan requested a review from anbuzin July 1, 2026 17:47
@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ai-python Ready Ready Preview, Comment Jul 1, 2026 5:48pm

@msullivan

Copy link
Copy Markdown
Contributor Author

maybe just tool_context?

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