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
- Define the action tool schema and set
tool_choice={"type":"tool","name":"print_sentiment_scores"}for the constrained step. [source05] - Inspect the returned tool name and validate its input against the schema before accepting the proposal. [source05]
- 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
- Anthropic API key and a downstream consumer that validates proposed actions before execution.
Permissions
- Use approved test or anonymized data only; scope credentials to each workflow, and require explicit approval for external writes.
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
- 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