llmsql-benchmark icon indicating copy to clipboard operation
llmsql-benchmark copied to clipboard

[Evaluation] `find_sql` drops the final query after reasoning text and truncates at `;` inside literals

Open DzmitryPihulski opened this issue 1 month ago • 1 comments

Problem

find_sql() (llmsql/utils/regex_extractor.py) has two extraction bugs:

  1. It keeps the first 10 candidates (results[:limit]). Every word starting with SELECT starts a candidate, so a model that explains or reasons before answering ("I need to select the right column...") fills the 10 slots with prose and the final query is never evaluated. Reproduced with 12 such sentences followed by a correct query: the query is not among the candidates.
  2. It cuts at the first ;, even inside string literals: SELECT a FROM "Table" WHERE b = 'x;y'; becomes SELECT a FROM "Table" WHERE b = 'x.

Related, for documentation: an item counts as correct if any of up to 10 extracted candidates matches the gold result, which favours models that output several queries. This should at least be documented, and the score of a single chosen query (first or last) could be reported next to it.

Proposal

  • Prefer the content of the last ```sql block when present; otherwise keep the last N candidates instead of the first N.
  • Make the end-of-query search ignore ; inside quoted strings.
  • Document the any-of-N rule in the evaluation docs; optionally add a single_query_accuracy metric.
  • Unit tests for both cases above.

DzmitryPihulski avatar Oct 05 '26 16:10 DzmitryPihulski

I'd like to take this one. Plan: in find_sql(), prefer the contents of ```sql blocks when present, otherwise keep the last N candidates instead of the first N; find the end of a query with a small scanner that skips quoted runs so a ; inside a string literal or quoted identifier is not treated as a terminator; document the any-of-N scoring rule in the evaluation docs and add unit tests for both cases. No changes to the any-of-N scoring itself.

ddaihao2022 avatar Oct 08 '26 15:10 ddaihao2022