bug: Bedrock silently drops names from ToolChoice::Specific
- I have looked for existing issues (including closed) about this
Bug Report
Rig's ToolChoice::Specific accepts a list of function names. In the Bedrock provider, a request with two or more names is converted into an AWS ToolChoice::Tool containing only the first name. The request is sent without an error, even though the caller's selection has changed. An empty list has a related problem: it produces a tool configuration without a specific choice. If there are no tool definitions, tools_config() returns None before either case is surfaced.
This matters when an application chooses a subset of its registered tools for a particular turn. For example, the caller may allow either lookup_order or request_refund, expecting the model to choose between those two. With Bedrock, only lookup_order reaches the service as the named choice. If the permitted names were assembled from user permissions or workflow state, the request no longer represents the restriction the application asked for. The caller sees neither a validation error nor a warning, so the behavior can look like a model preference rather than a request-conversion problem.
The conversion is in crates/rig-bedrock/src/types/completion_request.rs, inside AwsCompletionRequest::tools_config(). Its ToolChoice::Specific arm calls function_names.first() and builds one AWS SpecificToolChoice from that value. The AWS Bedrock ToolChoice::Tool shape has a single name; it cannot express Rig's multi-name choice in that form. The same tools_config() result is used by the Bedrock transport before both regular Converse requests and streamed Converse requests.
The cases differ in a way that matters to callers:
| Rig input | Current Bedrock conversion |
|---|---|
| One name | Sends that name as the specific AWS tool choice. |
| Two or more names | Sends only the first name and silently drops the rest. |
| Empty name list with tools | Builds the tools without a specific choice. |
| Invalid specific choice with no tools | Returns no tool configuration before validating the choice. |
Only the first row faithfully represents what the caller requested. In the other rows, success from request conversion makes it difficult to distinguish a provider decision from a locally changed request.
Reproduction
The following request state is sufficient to reproduce the conversion in a Bedrock crate unit test. The tool definitions can be ordinary valid object-schema tools; the important input is the tool_choice value:
let request = CompletionRequest {
tool_choice: Some(ToolChoice::Specific {
function_names: vec!["lookup_order".into(), "request_refund".into()],
}),
tools: vec![lookup_order_tool, request_refund_tool],
..minimal_request()
};
let config = AwsCompletionRequest::new(request, false)
.tools_config()
.expect("tool configuration builds")
.expect("tools are present");
assert!(matches!(
config.tool_choice(),
Some(aws_bedrock::ToolChoice::Tool(choice))
if choice.name() == "lookup_order"
));Before the proposed fix, that assertion describes the actual result: request_refund is discarded. Replacing the list with vec![] yields no specific AWS tool choice. The conversion can be inspected locally without AWS credentials or a network request.
To check the no-tools branch, use the same multi-name tool_choice with tools: vec![]. The current function returns Ok(None) for that input. This is a separate path through the same validation gap, so validation needs to happen before the empty-tools return.
Expected behavior
Bedrock should accept a ToolChoice::Specific request only when it contains exactly one function name, which maps directly to AWS's single named ToolChoice::Tool. For an empty list or a list with more than one name, request construction should return a ProviderError::Request with an actionable explanation before calling Bedrock. This check should still happen when the tools list is empty, so the invalid choice cannot disappear through the no-tools early return.
Screenshots
Not applicable; this is request conversion behavior.
Additional context
The one-name case already has a unit test and should keep its current mapping. The proposed regression coverage checks zero and multiple names with tools present, plus multiple names when no tools are configured. This is a provider-side validation change; Rig's shared ToolChoice type can continue to support providers that accept several named tools.
Callers that intend to force one particular Bedrock tool can provide one name. A caller that intends to let Bedrock choose among registered tools can use a supported broader choice, such as Auto or Required, depending on whether a tool call must happen. Failing early for unsupported cardinalities gives the application a chance to make that decision explicitly rather than narrowing a request without notice.
Source: 0xPlaygrounds/rig