Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

A nullable choice in a Gemini tool declaration carries a type (#102)

github-actions[bot]ade653e4524c
diff --git a/gateway/app.py b/gateway/app.py
index 4c0f42a0..b8ea4424 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -3181,6 +3181,21 @@ def _gemini_schema(node):
out["type"] = non_null[0] if non_null else "string"
if "null" in t:
out["nullable"] = True
+ if "type" not in out and isinstance(out.get("anyOf"), list):
+ # a nullable choice (zod's optional): the null member becomes `nullable`, one remaining member
+ # becomes the node itself, several keep anyOf under the first member's type; without a type
+ # the channel for gemini-3.5-flash answers "schema didn't specify the schema type field"
+ members = [m for m in out["anyOf"] if isinstance(m, dict) and m.get("type") != "null"]
+ if len(members) < len(out["anyOf"]):
+ out["nullable"] = True
+ if len(members) == 1:
+ out = {**members[0], **{k: v for k, v in out.items() if k != "anyOf"}}
+ out.setdefault("type", members[0].get("type", "string"))
+ elif members:
+ out["anyOf"] = members
+ out["type"] = members[0].get("type") or "string"
+ else:
+ out.pop("anyOf")
if "type" not in out and "anyOf" not in out:
out["type"] = "object" if "properties" in out else ("array" if "items" in out else "string")
if out.get("type") == "array" and "items" not in out:
diff --git a/gateway/tests/test_google_provider.py b/gateway/tests/test_google_provider.py
index d5ceb38c..2a8f7a73 100644
--- a/gateway/tests/test_google_provider.py
+++ b/gateway/tests/test_google_provider.py
@@ -125,7 +125,7 @@ def test_a_harness_tool_schema_is_normalised_to_googles_subset():
item = out["properties"]["files"]["items"]
assert item["properties"]["end_line"] == {"description": "line", "type": "string"}
assert item["properties"]["count"] == {"type": "integer", "minimum": 0}
- assert item["properties"]["mode"] == {"anyOf": [{"enum": ["a"], "type": "string"}, {"enum": ["b"], "type": "string"}]}
+ assert item["properties"]["mode"] == {"type": "string", "anyOf": [{"enum": ["a"], "type": "string"}, {"enum": ["b"], "type": "string"}]}
assert item["properties"]["tag"] == {"type": "string", "nullable": True}
assert item["required"] == ["path"]
assert out["properties"]["opts"] == {"type": "object"}
@@ -142,3 +142,11 @@ def test_only_tool_parameters_change_and_an_empty_declaration_is_dropped():
assert out["messages"] == [{"role": "user", "content": "hi"}]
plain = b'{"model": "google/gemini-3.8-flash", "messages": []}'
assert gw._with_gemini_schemas(plain) is plain
+
+
+def test_a_nullable_choice_gets_a_type():
+ # zod's optional integer: anyOf [integer, null] with no type; the 3.5-flash channel refuses it without one
+ assert gw._gemini_schema({"anyOf": [{"type": "integer"}, {"type": "null"}], "description": "line"}) == {"type": "integer", "nullable": True, "description": "line"}
+ two = gw._gemini_schema({"anyOf": [{"type": "string"}, {"type": "integer"}, {"type": "null"}]})
+ assert two["type"] == "string" and two["nullable"] is True and [m["type"] for m in two["anyOf"]] == ["string", "integer"]
+ assert gw._gemini_schema({"anyOf": [{"type": "null"}]}) == {"type": "string", "nullable": True}
diff --git a/runner/dsh_driver.py b/runner/dsh_driver.py
index b1464b4f..03ef6df5 100644
--- a/runner/dsh_driver.py
+++ b/runner/dsh_driver.py
@@ -140,6 +140,21 @@ def _gemini_schema(node):
out["type"] = non_null[0] if non_null else "string"
if "null" in t:
out["nullable"] = True
+ if "type" not in out and isinstance(out.get("anyOf"), list):
+ # a nullable choice (zod's optional): the null member becomes `nullable`, one remaining member
+ # becomes the node itself, several keep anyOf under the first member's type; without a type
+ # the channel for gemini-3.5-flash answers "schema didn't specify the schema type field"
+ members = [m for m in out["anyOf"] if isinstance(m, dict) and m.get("type") != "null"]
+ if len(members) < len(out["anyOf"]):
+ out["nullable"] = True
+ if len(members) == 1:
+ out = {**members[0], **{k: v for k, v in out.items() if k != "anyOf"}}
+ out.setdefault("type", members[0].get("type", "string"))
+ elif members:
+ out["anyOf"] = members
+ out["type"] = members[0].get("type") or "string"
+ else:
+ out.pop("anyOf")
if "type" not in out and "anyOf" not in out:
out["type"] = "object" if "properties" in out else ("array" if "items" in out else "string")
if out.get("type") == "array" and "items" not in out:
diff --git a/runner/server.py b/runner/server.py
index e8fcfda0..e4750ad9 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -2311,6 +2311,21 @@ def _gemini_schema(node):
out["type"] = non_null[0] if non_null else "string"
if "null" in t:
out["nullable"] = True
+ if "type" not in out and isinstance(out.get("anyOf"), list):
+ # a nullable choice (zod's optional): the null member becomes `nullable`, one remaining member
+ # becomes the node itself, several keep anyOf under the first member's type; without a type
+ # the channel for gemini-3.5-flash answers "schema didn't specify the schema type field"
+ members = [m for m in out["anyOf"] if isinstance(m, dict) and m.get("type") != "null"]
+ if len(members) < len(out["anyOf"]):
+ out["nullable"] = True
+ if len(members) == 1:
+ out = {**members[0], **{k: v for k, v in out.items() if k != "anyOf"}}
+ out.setdefault("type", members[0].get("type", "string"))
+ elif members:
+ out["anyOf"] = members
+ out["type"] = members[0].get("type") or "string"
+ else:
+ out.pop("anyOf")
if "type" not in out and "anyOf" not in out:
out["type"] = "object" if "properties" in out else ("array" if "items" in out else "string")
if out.get("type") == "array" and "items" not in out:
diff --git a/runner/tests/test_dsh_driver_gemini_schema.py b/runner/tests/test_dsh_driver_gemini_schema.py
index 431c3fc6..f6734973 100644
--- a/runner/tests/test_dsh_driver_gemini_schema.py
+++ b/runner/tests/test_dsh_driver_gemini_schema.py
@@ -22,7 +22,7 @@ def test_a_harness_tool_schema_is_normalised_to_googles_subset():
item = out["properties"]["files"]["items"]
assert item["properties"]["end_line"] == {"description": "line", "type": "string"}
assert item["properties"]["count"] == {"type": "integer", "minimum": 0}
- assert item["properties"]["mode"] == {"anyOf": [{"enum": ["a"], "type": "string"}, {"enum": ["b"], "type": "string"}]}
+ assert item["properties"]["mode"] == {"type": "string", "anyOf": [{"enum": ["a"], "type": "string"}, {"enum": ["b"], "type": "string"}]}
assert item["properties"]["tag"] == {"type": "string", "nullable": True}
assert item["required"] == ["path"]
assert out["properties"]["opts"] == {"type": "object"}
@@ -39,3 +39,11 @@ def test_only_tool_parameters_change_and_an_empty_declaration_is_dropped():
assert out["messages"] == [{"role": "user", "content": "hi"}]
plain = b'{"model": "google/gemini-3.8-flash", "messages": []}'
assert dsh_driver._with_gemini_schemas(plain) is plain
+
+
+def test_a_nullable_choice_gets_a_type():
+ # zod's optional integer: anyOf [integer, null] with no type; the 3.5-flash channel refuses it without one
+ assert dsh_driver._gemini_schema({"anyOf": [{"type": "integer"}, {"type": "null"}], "description": "line"}) == {"type": "integer", "nullable": True, "description": "line"}
+ two = dsh_driver._gemini_schema({"anyOf": [{"type": "string"}, {"type": "integer"}, {"type": "null"}]})
+ assert two["type"] == "string" and two["nullable"] is True and [m["type"] for m in two["anyOf"]] == ["string", "integer"]
+ assert dsh_driver._gemini_schema({"anyOf": [{"type": "null"}]}) == {"type": "string", "nullable": True}
diff --git a/runner/tests/test_relay_gemini_schema.py b/runner/tests/test_relay_gemini_schema.py
index 5de01bfc..4640adfc 100644
--- a/runner/tests/test_relay_gemini_schema.py
+++ b/runner/tests/test_relay_gemini_schema.py
@@ -22,7 +22,7 @@ def test_a_harness_tool_schema_is_normalised_to_googles_subset():
item = out["properties"]["files"]["items"]
assert item["properties"]["end_line"] == {"description": "line", "type": "string"}
assert item["properties"]["count"] == {"type": "integer", "minimum": 0}
- assert item["properties"]["mode"] == {"anyOf": [{"enum": ["a"], "type": "string"}, {"enum": ["b"], "type": "string"}]}
+ assert item["properties"]["mode"] == {"type": "string", "anyOf": [{"enum": ["a"], "type": "string"}, {"enum": ["b"], "type": "string"}]}
assert item["properties"]["tag"] == {"type": "string", "nullable": True}
assert item["required"] == ["path"]
assert out["properties"]["opts"] == {"type": "object"}
@@ -39,3 +39,11 @@ def test_only_tool_parameters_change_and_an_empty_declaration_is_dropped():
assert out["messages"] == [{"role": "user", "content": "hi"}]
plain = b'{"model": "google/gemini-3.8-flash", "messages": []}'
assert server._with_gemini_schemas(plain) is plain
+
+
+def test_a_nullable_choice_gets_a_type():
+ # zod's optional integer: anyOf [integer, null] with no type; the 3.5-flash channel refuses it without one
+ assert server._gemini_schema({"anyOf": [{"type": "integer"}, {"type": "null"}], "description": "line"}) == {"type": "integer", "nullable": True, "description": "line"}
+ two = server._gemini_schema({"anyOf": [{"type": "string"}, {"type": "integer"}, {"type": "null"}]})
+ assert two["type"] == "string" and two["nullable"] is True and [m["type"] for m in two["anyOf"]] == ["string", "integer"]
+ assert server._gemini_schema({"anyOf": [{"type": "null"}]}) == {"type": "string", "nullable": True}