Skip to content

feat: Surface newer data-dict spec fields in prompts and schema views (#316 follow-up) - #331

Open
cpsievert wants to merge 23 commits into
datadict-spec-alignmentfrom
datadict-phase2-context
Open

cpsievert wants to merge 23 commits into
datadict-spec-alignmentfrom
datadict-phase2-context

Conversation

@cpsievert

Copy link
Copy Markdown
Contributor

Stacked on #330 (phase 1, data-dict spec alignment) — review that PR first. #316 follow-up.

Summary

Wires the data-dict spec's newer descriptive fields into querychat's prompt and schema channels, in both packages:

  • Table-level constraints (assertion objects/barewords) are rendered in the get_schema tool response as a Table constraints: section.
  • Column label and time_zone appear as Label: / Time zone: annotations in the LLM schema text; label also passes through to the system-prompt data-dict block (both packages).
  • examples are shown in the schema text, capped at 5 with a … (N more) marker.
  • Map-form values labels are rendered as a trailing Labels: M=Male, F=Female annotation, keeping Categorical values: pure ('M', 'F') so the LLM writes SQL against real values.
  • display: restricted columns stay visible to the LLM (annotated [restricted: do not display in user-facing output], examples withheld) but are hidden from the user-facing schema card; queries are not blocked (soft restriction).
  • Relationship aliases / conflicts parse in pkg-py and pass through to the system-prompt data-dict YAML block in both packages.

pkg-py carries the new fields on ColumnMeta (label, time_zone, display, examples, value_labels) from DataDict.get_table_schema() through format_schema() and _schema_table(). pkg-r mirrors this with loose-list pass-throughs in build_column_details_impl(), format_schema_from_details() (which now takes an optional table_spec so all schema-text paths include table constraints), and schema_table().

Verification

  • New tests: test_new_field_parsing, test_get_table_schema_new_column_fields, test_to_prompt_dict_new_pass_throughs, test_format_schema_new_annotations, test_schema_card_hides_restricted_columns, test_get_schema_includes_table_constraints (py); "renders new dict fields and hides restricted columns from the card" (R).
  • pkg-py: 1010 tests pass, pyright clean, ruff clean; pkg-r: 2238 tests pass.

Copilot AI 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.

🟡 Changes recommended

R omits value-label annotations for numeric-coded columns, losing their meanings in the LLM schema.

1 open finding
What changed in this PR

Extends the data-dictionary alignment from #330, surfacing newer metadata in Python and R prompts and schema views.

Changes:

  • Adds descriptive annotations, value labels, examples, and table constraints.
  • Hides restricted columns from schema cards while retaining annotated LLM context.
  • Passes relationship metadata into prompts and adds tests and release notes.
File Description
pkg-r/​tests/​testthat/​test-querychat_tools.R Tests annotations and restricted-column hiding.
pkg-r/​tests/​testthat/​test-DataDict.R Tests prompt metadata pass-through.
pkg-r/​R/​TblSqlSource.R Passes table specifications to formatting.
pkg-r/​R/​QueryExecutor.R Passes table specifications to formatting.
pkg-r/​R/​querychat_tools.R Filters restricted schema-card columns.
pkg-r/​R/​DBISource.R Extracts and formats new metadata.
pkg-r/​R/​DataDict.R Preserves table labels and relationship metadata.
pkg-r/​NEWS.md Documents new metadata support.
pkg-py/​tests/​test_tools.py Tests constraints and restricted-column hiding.
pkg-py/​tests/​test_datasource.py Tests schema annotations.
pkg-py/​tests/​test_data_dict.py Tests parsing and metadata propagation.
pkg-py/​src/​querychat/​tools.py Adds constraints and filters schema cards.
pkg-py/​src/​querychat/​_datasource.py Stores and formats new column metadata.
pkg-py/​src/​querychat/​_data_dict.py Parses and propagates new dictionary fields.
pkg-py/​CHANGELOG.md Documents new metadata support.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg-r/R/DBISource.R Outdated
# Conflicts:
#	pkg-py/tests/test_datasource.py
#	pkg-py/tests/test_tools.py
Addresses Copilot review on #331: a values map on a numeric column
(e.g. {1: Low, 2: High}) was ignored because values handling lived in
the text-column branch, so the LLM lost the coding meanings. Spec
values now replace live stats/categorical inference for any column
kind, matching pkg-py.

Copilot AI 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.

🟡 Changes recommended

The R schema path still requests unused numeric/date statistics for dictionary-defined values, potentially causing unnecessary remote-table scans.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced

Comment thread pkg-r/R/DBISource.R
# Conflicts:
#	pkg-py/tests/test_data_dict.py
#	pkg-r/tests/testthat/test-querychat_tools.R
Addresses Copilot review on #331: a numeric/date column with values but
no range no longer uses live stats, so requesting them scanned remote
tables for nothing. When all columns are documented, the aggregate
query is now skipped entirely.
@cpsievert
cpsievert requested a balanced review from Copilot October 15, 2026 21:00
The data dictionary guide now covers table label/constraints, column
label/time_zone/examples/display, and relationship aliases/conflicts.
Changelog entries lead with what users can do rather than rendering
internals.

Copilot AI 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.

🟢 Approval recommended

No blocking defects were identified in the metadata propagation and schema-display changes.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced

Comment thread pkg-py/src/querychat/_data_dict.py Outdated
# Conflicts:
#	pkg-py/docs/context.qmd
#	pkg-r/R/DBISource.R
#	pkg-r/vignettes/context.Rmd
Addresses Copilot review on #331: module is already private, so helper
names don't need a leading underscore per project convention.

Copilot AI 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.

🟢 Approval recommended

The remaining feedback is limited to non-blocking documentation inaccuracies about where table labels appear.

2 open findings
1 resolved since last review

🧠 Review effort: Balanced

Comment thread pkg-py/docs/context.qmd Outdated
Each entry under `tables` describes one table. Its `name` must match the table name you pass to `QueryChat` or `.add_table()`.

- **`description`**: What this table represents (one sentence is usually enough).
- **`label`**: Optional display title, shown alongside the table in the schema view.
Comment thread pkg-r/vignettes/context.Rmd Outdated
Each entry under `tables` describes one table. Its `name` must match the table name you pass to `QueryChat$new()` or `$add_table()`.

- **`description`**: What this table represents (one sentence is usually enough).
- **`label`**: Optional display title, shown alongside the table in the schema view.

This branch has not been deployed

No deployments
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