larksuite/cli · error · LarkCliError

+csv-get truncated the requested range at {source_range}; na

Error message

+csv-get truncated the requested range at {source_range}; narrow --range before profiling

What it means

profile_table requires the FULL requested range to profile accurately. When the +csv-get call reports has_more=true, the returned data was truncated at actual_range, so profiling would run on partial data; the script refuses and tells you to narrow --range. It fails fast instead of producing misleading statistics.

Source

Thrown at skills/lark-sheets/scripts/lark_profile_table.py:550

        raise ValueError("--header-scan-rows must be at least 1")
    csv_data = envelope_data(
        run_sheets(
            "+csv-get",
            url=args.url,
            spreadsheet_token=args.spreadsheet_token,
            sheet_id=args.sheet_id,
            sheet_name=args.sheet_name,
            flags={
                "range": args.range,
                "max_chars": args.max_chars,
                "skip_hidden": True if args.skip_hidden else None,
            },
            timeout=args.timeout,
        )
    )
    source_range = str(csv_data.get("actual_range") or args.range)
    if csv_data.get("has_more"):
        raise LarkCliError(
            f"+csv-get truncated the requested range at {source_range}; narrow --range before profiling"
        )
    grid = parse_annotated_csv(
        csv_data.get("annotated_csv", ""),
        csv_data.get("col_indices"),
        csv_data.get("row_indices"),
        source_range,
    )
    if grid.row_numbers_inferred:
        warnings.append("CSV row numbers were inferred from the requested range")
    hidden_rows: list[int] = []
    hidden_columns: list[str] = []
    all_hidden_columns: list[str] | None = None
    # Fetched in BOTH modes. Under --skip-hidden the hidden rows/columns are
    # absent from the grid, so hidden_rows/hidden_columns (which are scoped to
    # what the grid contains) come back empty and no warning fires — but the
    # write hints still need to know where the hidden columns are, or
    # safe_append_col can point at one that holds data. all_hidden_columns is

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Pass a narrower --range that fits in one response, e.g. split A1:Z50000 into A1:Z20000, A20001:Z40000, etc.
  2. Profile per sheet/sub-range in a loop, merging results yourself.
  3. If the range looks right, verify the sheet dimensions; the truncation point is reported in the error (actual_range).

Example fix

# before
run(["lark", "sheets", "profile-table", "--range", "A1:Z100000"])
# after
run(["lark", "sheets", "profile-table", "--range", "A1:Z10000"])
run(["lark", "sheets", "profile-table", "--range", "A10001:Z20000"])
Defensive patterns

Strategy: validation

Validate before calling

def safe_range(sheet_rows: int, sheet_cols: int, max_cells: int = 1_000_000) -> str:
    if sheet_rows * sheet_cols > max_cells:
        raise ValueError(f"Range {sheet_rows}x{sheet_cols} exceeds {max_cells} cells; narrow --range")
    return f"A1:{index_to_col(sheet_cols)}{sheet_rows}"

Try / catch

try:
    data, warnings = profile_table(args)
except LarkCliError as e:
    if "truncated the requested range" in str(e):
        # narrow the range per the reported actual_range and retry in chunks
        args.range = narrow_range(args.range)
        data, warnings = profile_table(args)
    else:
        raise

Prevention

When it happens

Trigger: Running profile_table against a range larger than what +csv-get can return in one response: args.range spans too many cells/rows so csv_data['has_more'] is true.

Common situations: Profiling an entire huge sheet (e.g. --range A1:Z100000 on a sheet with tens of thousands of rows); downstream limits on the CSV export lowered so previously-fine ranges now truncate; a spreadsheet_token/sheet_id pointing at a much bigger sheet than expected.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/2db6f89cbf1314fb. Report an issue: GitHub.