Agent Wealth HubFree public resources
中文 EN العربية

Back to catalog / Agent workflows

Validate a note tool call before saving

Use Pydantic models to reject malformed note and author fields before a persistence adapter receives them.

Goal

Use Pydantic models to reject malformed note and author fields before a persistence adapter receives them.

Steps

  1. Define Author, Note, and SaveNoteResponse models; constrain priority to 1–5 and validate the email field. [source01]
  2. Parse the save_note tool input into Note before calling the storage adapter; convert validation failures into a bounded tool error. [source01]
  3. Test valid, missing-author, malformed-email, and out-of-range-priority calls; only the valid case reaches persistence. [source01]

How to verify

Send one valid note and three invalid payloads; confirm only the valid call reaches the persistence adapter and the other three return bounded validation errors.

Troubleshooting

If a malformed note is saved, move Pydantic parsing ahead of the adapter call; inspect the rejected field and ensure the error response contains no raw traceback.

Permissions

Prerequisites

Permissions

Limitations

Model output may be incomplete or wrong; API and beta behavior can change, so verify against the pinned source and current service behavior.

Pinned upstream source

https://github.com/anthropics/anthropic-cookbook/blob/9c1e493ddd2b82df399d2a61b9c806c539e18be6/tool_use/tool_use_with_pydantic.ipynb

Repository
anthropics/anthropic-cookbook
File path
tool_use/tool_use_with_pydantic.ipynb
Pinned commit
9c1e493ddd2b82df399d2a61b9c806c539e18be6
Source checked
2026-10-14 · Reviewed against the pinned upstream source

Repository metrics

These values describe the upstream repository, not popularity or likes for an individual skill or playbook.

Stars
Not collected
Forks
Not collected
Observed at
Not collected

No metrics snapshot is available yet.

License: MIT

Main topic

Turn ecommerce campaign materials into a reviewable weekly brief

Related resources