mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-05 12:48:12 +00:00
core[patch]: raise error if a tool call has an empty tool call ID
This commit is contained in:
parent
1fa9f6bc20
commit
c1888bd9d8
@ -934,6 +934,13 @@ def _prep_run_args(
|
|||||||
config = ensure_config(config)
|
config = ensure_config(config)
|
||||||
if _is_tool_call(input):
|
if _is_tool_call(input):
|
||||||
tool_call_id: Optional[str] = cast(ToolCall, input)["id"]
|
tool_call_id: Optional[str] = cast(ToolCall, input)["id"]
|
||||||
|
if not tool_call_id:
|
||||||
|
msg = (
|
||||||
|
"Tool call ID must be a non-empty string. "
|
||||||
|
f"Got '{tool_call_id}' for tool call '{input}'."
|
||||||
|
)
|
||||||
|
raise ValueError(msg)
|
||||||
|
|
||||||
tool_input: Union[str, dict] = cast(ToolCall, input)["args"].copy()
|
tool_input: Union[str, dict] = cast(ToolCall, input)["args"].copy()
|
||||||
else:
|
else:
|
||||||
tool_call_id = None
|
tool_call_id = None
|
||||||
|
@ -2457,3 +2457,22 @@ def test_simple_tool_args_schema_dict() -> None:
|
|||||||
assert tool.args == {
|
assert tool.args == {
|
||||||
"a": {"title": "A", "type": "integer"},
|
"a": {"title": "A", "type": "integer"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_empty_tool_call_id() -> None:
|
||||||
|
@tool
|
||||||
|
def foo(x: int) -> str:
|
||||||
|
"""Foo."""
|
||||||
|
return "hi"
|
||||||
|
|
||||||
|
for empty_tool_call_id in (None, ""):
|
||||||
|
with pytest.raises(
|
||||||
|
ValueError,
|
||||||
|
match=(
|
||||||
|
"Tool call ID must be a non-empty string. "
|
||||||
|
f"Got '{empty_tool_call_id}' for tool call '.*'."
|
||||||
|
),
|
||||||
|
):
|
||||||
|
foo.invoke(
|
||||||
|
{"type": "tool_call", "args": {"x": 0}, "id": empty_tool_call_id}
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user