Skip to content

Commit db96f8e

Browse files
fix: enforce max_length guarantee when single row exceeds limit
Co-Authored-By: Itamar Hartstein <haritamar@gmail.com>
1 parent 659064f commit db96f8e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

elementary/utils/json_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ def list_of_dicts_to_markdown_table(
151151
if len(table) <= effective_max:
152152
return table + truncation_note
153153

154-
# Even a single row doesn't fit — return what we can with a note
154+
# Even a single row doesn't fit — hard-truncate and append note
155155
single_row_table = tabulate(
156156
processed_data[:1],
157157
headers="keys",
158158
tablefmt="github",
159159
disable_numparse=True,
160160
)
161-
return single_row_table + truncation_note
161+
if effective_max <= 0 or len(single_row_table) <= effective_max:
162+
return single_row_table + truncation_note
163+
return single_row_table[:effective_max].rstrip() + truncation_note

0 commit comments

Comments
 (0)