[Evaluation] `find_sql` drops the final query after reasoning text and truncates at `;` inside literals
Problem
find_sql() (llmsql/utils/regex_extractor.py) has two extraction bugs:
- It keeps the first 10 candidates (
results[:limit]). Every word starting withSELECTstarts 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. - It cuts at the first
;, even inside string literals:SELECT a FROM "Table" WHERE b = 'x;y';becomesSELECT 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
```sqlblock 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_accuracymetric. - Unit tests for both cases above.
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.