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

Back to catalog / Agent workflows

Require a specific action tool for a workflow

Use tool_choice to enforce a typed handoff when every request must produce a machine-consumable action proposal.

Goal

Use `tool_choice` to enforce a typed handoff when every request must produce a machine-consumable action proposal.

Steps

  1. Define the action tool schema and set tool_choice={"type":"tool","name":"print_sentiment_scores"} for the constrained step. [source05]
  2. Inspect the returned tool name and validate its input against the schema before accepting the proposal. [source05]
  3. Add a fallback path with {"type":"auto"} when natural-language answers are allowed, and test irrelevant or adversarial prompts. [source05]

How to verify

With tool_choice forced, verify the returned block names print_sentiment_scores and still validate its fields; with auto mode, confirm a relevant text answer remains possible.

Troubleshooting

If an unrelated prompt produces a malformed action, reject it after schema validation and use the documented auto/fallback path; tool_choice enforces routing, not factual correctness.

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_choice.ipynb

Repository
anthropics/anthropic-cookbook
File path
tool_use/tool_choice.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

Take a coding Agent change from context to verification

Related resources