From c67101b041178999fbaa1794534439720cd25502 Mon Sep 17 00:00:00 2001 From: S2D2 Date: Tue, 10 Nov 2026 20:42:39 +0000 Subject: [PATCH 1/2] fix(tools): forward explicit nulls through the LangChain adapter to_langchain() dropped every None argument because, with the old pydantic args_schema, BaseTool materialised each unsupplied optional as None. The schema has been a plain JSON Schema dict since the MCP-only toolset, and on langchain-core 1.6.3 BaseTool passes exactly what the model sent: an omitted optional is absent, an explicit null is null. The filter now only removed nulls the model chose to send, which the OpenAI and Pydantic AI adapters forward. Forward the arguments as given. Co-Authored-By: Claude Opus 5.5 Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com> --- stackone_ai/tools.py | 10 ++++------ tests/test_fetch_tools.py | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/stackone_ai/tools.py b/stackone_ai/tools.py index 486b6aa..65048a5 100644 --- a/stackone_ai/tools.py +++ b/stackone_ai/tools.py @@ -1301,13 +1301,11 @@ class StackOneLangChainTool(BaseTool): args_schema: dict[str, Any] = args_json_schema # ty: ignore[invalid-assignment] def _run(self, **kwargs: Any) -> Any: - # Drop unsupplied optionals. pydantic materialises every optional field - # as None and BaseTool passes them all through, and the API reads an - # explicit null as "required field missing" — which 400'd every single - # tool call made through this adapter. - supplied = {key: value for key, value in kwargs.items() if value is not None} + # args_schema is a JSON Schema dict, not a pydantic model, so BaseTool + # hands over exactly what the model sent: an omitted optional stays + # absent and an explicit null stays null, as to_pydantic_ai_tool forwards it. try: - return parent_tool.execute(supplied) + return parent_tool.execute(kwargs) except (StackOneError, ValueError) as exc: # LangChain's handle_tool_error only catches ToolException, so a # StackOneError would kill the graph rather than reaching the diff --git a/tests/test_fetch_tools.py b/tests/test_fetch_tools.py index e849270..528786f 100644 --- a/tests/test_fetch_tools.py +++ b/tests/test_fetch_tools.py @@ -2038,15 +2038,24 @@ def test_langchain_raises_tool_exception_carrying_the_response_body(self, monkey tool.to_langchain()._run(path_id="x") assert excinfo.value.status_code == 400 - def test_langchain_does_not_forward_unsupplied_optionals_as_null(self, monkeypatch): - """The API reads an explicit null as "required field missing", so this 400'd every call.""" + @pytest.mark.parametrize( + ("sent", "forwarded"), + [ + # An omitted optional must not arrive as null: the API reads a null as a value. + ({"path_id": "x"}, {"path_id": "x"}), + # A null the model chose to send is its argument, forwarded as with every adapter. + ({"path_id": "x", "body_after": None}, {"path_id": "x", "body_after": None}), + ], + ) + def test_langchain_forwards_the_model_arguments_as_sent(self, monkeypatch, sent, forwarded): from stackone_ai.tools import StackOneMcpTool seen: dict[str, object] = {} tool, _ = self._failing_tool() + tool.parameters.properties["body_after"] = {"type": ["string", "null"]} monkeypatch.setattr(StackOneMcpTool, "execute", lambda _self, args=None: seen.update(args=args) or {}) - tool.to_langchain()._run(path_id="x", body_after=None) - assert seen["args"] == {"path_id": "x"} + tool.to_langchain().invoke({"name": tool.name, "args": sent, "id": "call-1", "type": "tool_call"}) + assert seen["args"] == forwarded def test_pydantic_ai_raises_model_retry(self, monkeypatch): pytest.importorskip("pydantic_ai") From ab6f7519141281fea150ed76c80ff04f5765fa50 Mon Sep 17 00:00:00 2001 From: S2D2 Date: Wed, 11 Nov 2026 00:33:51 +0000 Subject: [PATCH 2/2] refactor(tools): tighten the LangChain forwarding comment and test ids Two lines of comment now carry the whole contract, and the two test cases are named by pytest ids instead of inline comments. No behaviour change. Co-Authored-By: Claude Opus 5.5 Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com> --- stackone_ai/tools.py | 5 ++--- tests/test_fetch_tools.py | 10 ++++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/stackone_ai/tools.py b/stackone_ai/tools.py index 65048a5..bcb7b12 100644 --- a/stackone_ai/tools.py +++ b/stackone_ai/tools.py @@ -1301,9 +1301,8 @@ class StackOneLangChainTool(BaseTool): args_schema: dict[str, Any] = args_json_schema # ty: ignore[invalid-assignment] def _run(self, **kwargs: Any) -> Any: - # args_schema is a JSON Schema dict, not a pydantic model, so BaseTool - # hands over exactly what the model sent: an omitted optional stays - # absent and an explicit null stays null, as to_pydantic_ai_tool forwards it. + # args_schema is a JSON Schema dict, so BaseTool passes the model's arguments + # through untouched: an omitted optional stays absent, an explicit null stays null. try: return parent_tool.execute(kwargs) except (StackOneError, ValueError) as exc: diff --git a/tests/test_fetch_tools.py b/tests/test_fetch_tools.py index 528786f..0a9fc03 100644 --- a/tests/test_fetch_tools.py +++ b/tests/test_fetch_tools.py @@ -2041,10 +2041,12 @@ def test_langchain_raises_tool_exception_carrying_the_response_body(self, monkey @pytest.mark.parametrize( ("sent", "forwarded"), [ - # An omitted optional must not arrive as null: the API reads a null as a value. - ({"path_id": "x"}, {"path_id": "x"}), - # A null the model chose to send is its argument, forwarded as with every adapter. - ({"path_id": "x", "body_after": None}, {"path_id": "x", "body_after": None}), + pytest.param({"path_id": "x"}, {"path_id": "x"}, id="omitted-optional-stays-absent"), + pytest.param( + {"path_id": "x", "body_after": None}, + {"path_id": "x", "body_after": None}, + id="explicit-null-is-forwarded", + ), ], ) def test_langchain_forwards_the_model_arguments_as_sent(self, monkeypatch, sent, forwarded):