mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-04-30 23:02:50 +00:00
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:
@@ -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
|
||||
|
||||
@@ -118,7 +118,7 @@ def _preprocess_structured_data(
|
||||
|
||||
|
||||
try:
|
||||
from aiobotocore.session import ( # type: ignore[import-untyped]
|
||||
from aiobotocore.session import (
|
||||
get_session as get_aiobotocore_session,
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user