Skip to content

Warn when a result fills its LIMIT, explain invalid values (v1.9.2) - #22

Merged
christophdb merged 1 commit into
mainfrom
limit-and-value-hints
Nov 4, 2026
Merged

christophdb merged 1 commit into
mainfrom
limit-and-value-hints

Conversation

@christophdb

Copy link
Copy Markdown
Member

Why

Testing the AI chat plugin with a smaller self-hosted model answered all seven test prompts correctly, but showed two gaps:

  1. Explicit LIMIT 100: the model set it by itself in most queries. The truncation notice from 1.9.0 only covers statements without LIMIT, so a result cut at an explicit 100 goes unnoticed. With more than 100 matching rows, an answer like "these customers have no order" would be silently incomplete.
  2. failed to convert value: invalid value: a select value in the wrong case ('Inaktiv' instead of 'inaktiv') fails with a message that names neither the column nor the cause. The model recovered through get_schema here, but the error gives it nothing to go on.

What changes

Truncation notice (truncationNotice())

Statement Rows Notice
no LIMIT 100 as before
LIMIT 100 or more exactly the limit "may be incomplete, raise LIMIT"
LIMIT 10000 or higher 10,000 "maximum reached, read further with OFFSET or use COUNT, SUM, GROUP BY"
LIMIT below 100 (a deliberate top-N) any none

The instructions and the query_sql description now say LIMIT 100 is no better than none, use LIMIT 10000 to read all rows, and prefer COUNT, SUM and GROUP BY.

A false alarm is possible when a table has exactly as many rows as the limit. It costs one extra query and gives no wrong answer.

Hint on invalid values
failed to convert value and type mismatch now get: "a value does not fit its column type. Select columns accept only existing options, spelled exactly (get_schema lists them); dates need the format YYYY-MM-DD". They count under the new reason invalid_value. execute_sql's description says the same up front.

Version 1.9.2.

Verified against SeaTable 7.0.11

Check Result
LIMIT 100 on 150 rows 100 rows, notice
LIMIT 1000 on 150 rows 150 rows, no notice
ORDER BY … LIMIT 3 3 rows, no notice
no LIMIT 100 rows, notice
LIMIT 100 OFFSET 100, LIMIT 100, 100 both work, the remaining 50 rows
SET Status = 'Inaktiv' (option is inaktiv) error + hint, reason invalid_value
SET Seit = '15.01.2026' error + hint, 2026-01-15 works
SET Umsatz = 'abc' type mismatch + hint
SET Status = 'inaktiv' OK

The 10,000 row maximum is covered by unit tests only; the local test table has 150 rows. npm test (381), typecheck, lint and build pass.

🤖 Generated with Claude Code

Testing the AI chat plugin with a smaller self-hosted model showed two
gaps:

- The model set LIMIT 100 by itself in most queries. The truncation
  notice only covered statements without LIMIT, so a result cut at an
  explicit 100 went unnoticed. The notice now also appears when the row
  count equals a LIMIT of 100 or more, and at the 10,000 row maximum,
  where it points to OFFSET. A smaller LIMIT is a deliberate top-N and
  stays quiet. The instructions now say LIMIT 100 is no better than none
  and prefer COUNT, SUM and GROUP BY.
- A select value in the wrong case failed with "failed to convert value:
  invalid value", which names neither the column nor the cause. Those
  errors and "type mismatch" now get a hint on options and the date
  format, and count under the new reason invalid_value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@christophdb
christophdb merged commit 4655a21 into main Nov 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant