fix: forward strict mode to Anthropic and Bedrock providers

The OpenAI-format tool schema sets strict: true but this was dropped
during conversion to Anthropic/Bedrock formats, so neither provider
used constrained decoding. Without it, the model can return string
"None" instead of JSON null for nullable fields, causing Pydantic
validation failures.
This commit is contained in:
Greyson LaLonde
2026-04-10 15:32:54 +08:00
committed by GitHub
parent fc6792d067
commit 6efa142e22
4 changed files with 170 additions and 122 deletions

View File

@@ -74,8 +74,8 @@ qdrant = [
"qdrant-client[fastembed]~=1.14.3",
]
aws = [
"boto3~=1.40.38",
"aiobotocore~=2.25.2",
"boto3~=1.42.79",
"aiobotocore~=3.4.0",
]
watson = [
"ibm-watsonx-ai~=1.3.39",
@@ -87,7 +87,7 @@ litellm = [
"litellm~=1.83.0",
]
bedrock = [
"boto3~=1.40.45",
"boto3~=1.42.79",
]
google-genai = [
"google-genai~=1.65.0",

View File

@@ -494,6 +494,10 @@ class AnthropicCompletion(BaseLLM):
"required": [],
}
func_info = tool.get("function", {})
if func_info.get("strict"):
anthropic_tool["strict"] = True
anthropic_tools.append(anthropic_tool)
return anthropic_tools

View File

@@ -169,6 +169,7 @@ class ToolSpec(TypedDict, total=False):
name: Required[str]
description: Required[str]
inputSchema: ToolInputSchema
strict: bool
class ConverseToolTypeDef(TypedDict):
@@ -1965,6 +1966,10 @@ class BedrockCompletion(BaseLLM):
input_schema: ToolInputSchema = {"json": parameters}
tool_spec["inputSchema"] = input_schema
func_info = tool.get("function", {})
if func_info.get("strict"):
tool_spec["strict"] = True
converse_tool: ConverseToolTypeDef = {"toolSpec": tool_spec}
converse_tools.append(converse_tool)