Skip to content

Validate tool results with return types#190

Merged
msullivan merged 1 commit into
mainfrom
tool-load
Jul 6, 2026
Merged

Validate tool results with return types#190
msullivan merged 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.

@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 6, 2026 4:23pm

@msullivan

Copy link
Copy Markdown
Contributor Author

maybe just tool_context?

@msullivan

Copy link
Copy Markdown
Contributor Author

And should we re-export it at just ai.tool_context?

@anbuzin

anbuzin commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

imo it belongs under ai.messages, you call it when you're messing with messages anyway

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_context([weather]),
)
```

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

Happy to bikeshed about names.
@msullivan
msullivan merged commit 80b906b into main Jul 6, 2026
7 checks passed
@msullivan
msullivan deleted the tool-load branch July 6, 2026 16:36
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