Skip to content

feat: make table sample data in SQL prompts configurable - #1359

Closed
moonbrigt wants to merge 1 commit into
dataease:mainfrom
moonbrigt:feat/configurable-table-sample-data
Closed

feat: make table sample data in SQL prompts configurable#1359
moonbrigt wants to merge 1 commit into
dataease:mainfrom
moonbrigt:feat/configurable-table-sample-data

Conversation

@moonbrigt

Copy link
Copy Markdown

When generating SQL, SQLBot currently fetches up to three sample rows from selected tables and includes them in the model context. This adds a TABLE_SAMPLE_DATA_ENABLED setting so deployments can disable that automatic sample context.

Closes #1291.

Changes

  • Default to true to preserve existing behavior and the three-row sample limit.
  • When false, return from automatic sampling before reading table metadata or sample rows, and omit sample values from SQL prompt rendering even when sample_data was populated earlier. Copy the template before changing it so the cached template is preserved.
  • Preserve schema context, explicit SQL execution, and manual previews.
  • Document environment and Docker configuration, restart requirements, and the scope of the setting.

This setting only controls automatic table samples in SQL-generation context. User messages, field comments, SQL examples, query results, and analysis prompts can still contain business data; this is not a global data-loss-prevention switch.

Validation

  • Passed: all 23 focused regression tests on CPython 3.11.16 under WSL Ubuntu (python -m pytest -q tests/test_table_sample_data.py), with pytest and Pydantic dependencies in an isolated uv environment.
  • Passed: git diff HEAD^ HEAD --check.
  • Reviewed the sampling call site, SQL prompt construction, and cached template handling.

The regression tests execute actual source function definitions with dependency doubles and use the real Pydantic settings loader. They cover configuration parsing, skipped sampling, existing sampling behavior, sample exclusion, template cache preservation, and unaffected schema/query/preview behavior. They do not validate full application imports or integration with external services.

Submitting as a draft because full application startup, real database/model-provider integration, MCP/embedded entry points, and full dependency integration have not been tested. Lint and type checks have not been run. CI status is not claimed as passed.

Add a default-on TABLE_SAMPLE_DATA_ENABLED setting. When disabled, skip
automatic sample queries and omit sample values from SQL prompt templates.
Preserve schema context and explicit query/preview behavior.

Add isolated regression tests and document configuration and limitations.

Refs #1291
@moonbrigt moonbrigt closed this by deleting the head repository Sep 9, 2026
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.

[FEATURE] 支持配置是否向大模型发送表前3条样本数据

1 participant