Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions bench/accuracy/mcp-review-results/failure-only-ce8e4a0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"revision": "ce8e4a0",
"scope": "only previously wrong cases; repair rate, not whole-set accuracy",
"model": "gpt-6.2-sol",
"reasoning_effort": "high",
"results": {
"bird": {
"correct": 0,
"total": 1,
"cases": [
{
"instance_id": "bird146",
"score": 0,
"status": "predicted"
}
],
"record_sha256": {
"bird146": "76645cd9175f3f442c8d9a5e44d7785f12efa6f652100f9f3ca12e5f96c80093"
}
},
"spider": {
"correct": 1,
"total": 10,
"cases": [
{
"instance_id": "local064",
"score": 0,
"pred_sql": null,
"error_info": "Result Error"
},
{
"instance_id": "local073",
"score": 0,
"pred_sql": null,
"error_info": "Result Error"
},
{
"instance_id": "local003",
"score": 0,
"error_info": "ValueError"
},
{
"instance_id": "local041",
"score": 1,
"pred_sql": null,
"error_info": null
},
{
"instance_id": "local062",
"score": 0,
"pred_sql": null,
"error_info": "Result Error"
},
{
"instance_id": "local202",
"score": 0,
"error_info": "ValueError"
},
{
"instance_id": "local279",
"score": 0,
"pred_sql": null,
"error_info": "Result Error"
},
{
"instance_id": "local264",
"score": 0,
"pred_sql": null,
"error_info": "Result Error"
},
{
"instance_id": "local194",
"score": 0,
"pred_sql": null,
"error_info": "Result Error"
},
{
"instance_id": "local335",
"score": 0,
"pred_sql": null,
"error_info": "Result Error"
}
],
"record_sha256": {
"local062": "ffede31afea381c1ef6a5f47b962f5e9ff32e4d0520eef7aa40315597bd57c06",
"local279": "a60294807fff23779f52873a0cad92edf617d86f633ca9c2d1dceb85117d32b3",
"local003": "d918195bb9478673e8c668cf1e51ca1387819bfbbe133c49459a9fdef349e97b",
"local202": "98f1850e5ca1c78f710bf2133044fe009515a7d4a72fedbcb1d5e6194869acf8",
"local064": "5d79df008d9a4263f7c7beffada5b8533caed9d9188fdb83e8cd7cbe0f23434c",
"local073": "0a594eafaabe2e481a3c32d2d373034cc33de20e97894f23678018986b9cd99a",
"local264": "29cdb14ea1d15c6772cd42e91e95c0a44ed00579b8e94128390250363d1e46ef",
"local194": "51f45c9d132bc7841396ad9d0bc948aa304e9e0b66d49fc6e1bba2ad023e9b19",
"local335": "9ed81fa6c16b6ad870f57b99a8b50acc043d5e72b785c5ccb97dd38e70615f7b",
"local041": "6515084632cba70e1affe3c8098bed2161cbe46a667cf9ccbf65597ab6706898"
}
}
}
}
12 changes: 10 additions & 2 deletions src/lang2sql/tools/run_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def spec(self) -> ToolSpec:
},
"limit": {
"type": "integer",
"description": "max rows (default 1000)",
"minimum": 1,
"description": "Positive maximum number of rows to fetch (default 1000); unlike SQLite SQL LIMIT, -1 is not supported.",
},
},
},
Expand Down Expand Up @@ -111,7 +112,7 @@ async def run(self, args: dict[str, Any], ctx: HarnessContext) -> ToolResult:
)
sql = (args.get("sql") or "").strip()
try:
limit = int(args.get("limit") or 1000)
limit = int(args.get("limit", 1000))
except (TypeError, ValueError) as exc:
logger.warning(
"invalid row limit scope=%s error=%s: %s",
Expand All @@ -121,6 +122,13 @@ async def run(self, args: dict[str, Any], ctx: HarnessContext) -> ToolResult:
)
limit = 1000 # tolerate a malformed limit from the model

if limit <= 0:
logger.warning("invalid nonpositive row limit scope=%s", ctx.identity.session_key())
return ToolResult(
call_id="", is_error=True,
content="Invalid limit: supply a positive maximum row count. SQL was NOT executed.",
)

if ctx.safety is None:
return ToolResult(
call_id="",
Expand Down
19 changes: 19 additions & 0 deletions tests/test_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,22 @@ async def test_missing_definitions_are_reported_together_and_revoke_receipt(tmp_
"sql": "SELECT COUNT(*) FROM orders", "definition_check_id": token
})
assert rejected.isError


@pytest.mark.asyncio
@pytest.mark.parametrize("limit", [-1, 0])
async def test_invalid_fetch_limit_rejected_before_database_access(tmp_path, limit):
from unittest.mock import AsyncMock

from lang2sql.tools.run_sql import RunSQL

explorer = AsyncMock()
ctx = build_tool_context(Identity(user_id="analyst", guild_id="demo"), store_path=":memory:", explorer=explorer)
try:
result = await RunSQL().run({"sql": "SELECT 1", "limit": limit}, ctx)
assert result.is_error
assert "positive maximum row count" in result.content
explorer.execute.assert_not_called()
assert RunSQL().spec.parameters["properties"]["limit"]["minimum"] == 1
finally:
ctx.store.close()