Skip to content

fix(llm): build /llm schema without GROUP_CONCAT truncation - #2492

Merged
rolandwalker merged 1 commit into
dbcli:mainfrom
pcbeingused33:fix/llm-schema-group-concat
Dec 3, 2026
Merged

rolandwalker merged 1 commit into
dbcli:mainfrom
pcbeingused33:fix/llm-schema-group-concat

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

Description

get_schema() in the /llm special command built each table's line of the
schema prompt with GROUP_CONCAT(column_name, ' ', COLUMN_TYPE SEPARATOR ', ').
MySQL silently truncates GROUP_CONCAT results at group_concat_max_len,
which is 1024 bytes by default on MySQL 8 (with only a warning), so for
tables with many columns the schema sent to the LLM lost its trailing columns
and the closing parenthesis. The GROUP_CONCAT also had no ORDER BY, so the
column order within a table was not guaranteed.

The query now selects table_name, column_name, COLUMN_TYPE from
information_schema.columns ordered by table_name, ordinal_position, and
the columns are grouped per table in Python. The output format is the same
(table(col type, col type)), with no length limit and columns in
definition order.

Tests: added test_get_schema_groups_columns_without_group_concat_truncation
(a 100-column table whose concatenated definition is well over 1024 bytes,
plus a second table), and updated the two existing dummy cursors to return
per-column rows. The new test fails on main and passes with the change;
mycli_test/pytests/test_special_llm.py passes (34 tests).

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the mycli/AUTHORS.txt file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

This PR was prepared with the assistance of Claude Code (AI).

GROUP_CONCAT output is silently cut at group_concat_max_len (1024 bytes
by default on MySQL), so wide tables lost columns in the schema sent to
the LLM. Fetch columns ordered by table and ordinal position and group
them in Python instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@rolandwalker rolandwalker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!

@rolandwalker
rolandwalker merged commit b8a0e05 into dbcli:main Dec 3, 2026
13 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.

2 participants