Skip to content

Keep LLM sample data text when only prompt_section_truncate is set - #2468

Merged
rolandwalker merged 1 commit into
dbcli:mainfrom
goranai:fix/llm-section-truncate
Nov 25, 2026
Merged

rolandwalker merged 1 commit into
dbcli:mainfrom
goranai:fix/llm-section-truncate

Conversation

@goranai

@goranai goranai commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #2467.

With only prompt_section_truncate set in the [llm] section, \llm sent every text and binary value of the sample rows as an empty string. The myclirc suggests prompt_section_truncate = 1000000 by itself, and prompt_field_truncate defaults to None, which the config reader turns into 0. truncate_list_elements then started its loop with width = 0, so every value was cut to x[:0].

Now, when no field limit is set, the width starts at the longest text value, but never above the section limit. The existing loop shrinks it in steps of 100 until the row fits prompt_section_truncate, so the section cap still works. Starting no higher than the section limit also keeps a very large blob from looping for a long time.

Reproduced on main (d226c7b) without a MySQL server, by calling sql_using_llm with a stub cursor and a spy on truncate_list_elements. Before: sample_data = {'users': [('id', 1), ('name', ''), ('note', '')]}. After: ('name', 'alice'), ('note', 'hello world').

Behavior changes:

  • Only when the field limit is 0 and the section limit is above 0. Other combinations return the same rows as before.
  • Rows that fit are now sent whole instead of blanked. Rows that do not fit are shortened to a common width, as in the field plus section case.
  • A row whose text columns do not fit still takes one pass of the 100 step loop. Many columns that are each near the section limit can take a few seconds (5 columns of 1 MB took 2.9 s, 20 columns of 1 MB took 11.5 s). A single huge value is instant.

Tests: test_truncate_list_elements_and_table_lines has new cases and fails on main, passes with the fix. mycli_test/pytests/test_special_llm.py: 30 passed. I also compared the fixed function with main and with a property check on 120000 random rows. Nothing changed when the field limit is set or the section limit is 0, and no row broke the property (text cut to one width, the row fits, and the next wider step would not). ruff check and ruff format --check pass. mypy reports 4 errors that are also on main (Windows only: pwd, signal.killpg). On Windows the whole suite shows 86 failures with and without this change.

Validated with Claude Opus 5.5.

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 .

@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.

Thank you!

@rolandwalker
rolandwalker merged commit 57db027 into dbcli:main Nov 25, 2026
13 checks passed
@rolandwalker

Copy link
Copy Markdown
Contributor

@goranai your PRs are really appreciated. Do you plan to make more? Contact me by email if you want to join the dbcli developer's Slack.

@rolandwalker

Copy link
Copy Markdown
Contributor

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.

LLM: keep sample data text when only prompt_section_truncate is set

2 participants