Skip to content

feat: Improving tableSchema AI tools - #683

Merged
ilyabo merged 18 commits into
mainfrom
tableSchema-tools
Jun 17, 2026
Merged

ilyabo merged 18 commits into
mainfrom
tableSchema-tools

Conversation

@ilyabo

@ilyabo ilyabo commented Jun 3, 2026 •

Copy link
Copy Markdown
Collaborator

Reworks AI table schema context so large database catalogs stay usable without overloading the model prompt, while preserving reliable table identity across AI tools, dashboard agents, and chart rendering.

This PR keeps the existing list_tables / read_table_schema tool surface from main, removes the parallel describe_table_schema implementation, and updates the default AI instructions to guide agents toward the existing table discovery workflow.

  • Core table context improvements

    • Added column types to AI-visible schema context.
    • Switched to a hybrid approach: full schemas for a few tables, summaries for the rest.
    • Avoids dumping every table schema into the prompt for large catalogs.
    • Added usable tableId values to schema summaries and full-schema headers.
  • Incorporated from PR feat: Allow maxChars parameter in formatTablesForLLM function #723

    • Added maxChars support for schema context.
    • Added a compact fallback when full schemas exceed the budget.
    • Fixed the currentDatabase edge case to avoid over-filtering tables.
  • Tooling / agent behavior

    • Agents fetch omitted schemas with read_table_schema.
    • list_tables and schema summaries expose usable, fully quoted tableId strings derived from QualifiedTableName.toString().
    • read_table_schema accepts unique bare table names for compatibility, but reports ambiguity instead of silently choosing when names collide.
    • Removed unsupported scope guidance for list_tables; prompts now reference only supported filters.
  • Canonical table identity

    • Uses the existing QualifiedTableName type as the canonical structured table identity.
    • Treats tableName as user input / display / legacy compatibility.
    • For string-only tool boundaries, forwards the fully quoted table id, e.g. "db"."schema"."table".
    • Ensures agents do not resolve a table and then continue forwarding only a bare display name when canonical identity is available.
  • Dashboard and chart behavior

    • Dashboard AI now sees tables across visible databases/schemas instead of only the current database’s main schema.
    • Dashboard table resolution accepts natural bare names when unique and reports ambiguity with canonical options when not.
    • Dashboard agents forward resolved qualified table ids to downstream tools.
    • Chart specs, component chart renderers, and chart data policies now use the qualified table reference instead of the bare table name, avoiding wrong-table rendering when attached databases contain duplicate table names.
  • CI / maintenance

    • Added focused tests for schema context, table identity resolution, ambiguity handling, dashboard agent forwarding, and qualified chart specs.
    • Added the missing ts-jest package dependency for @sqlrooms/ai tests.
    • Replaced the third-party semantic PR title action with local workflow validation.

Summary by CodeRabbit

  • New Features
    • AI assistant now provides richer, scope-aware table/schema context using fully qualified canonical table identifiers; dashboard and AI tool outputs/prompting align to the resolved table identity.
    • Chart queries now consistently target the table reference derived from the selected data table.
  • Bug Fixes
    • Improved local file schema refresh error messaging with a safe unknown-error fallback.
    • Table/schema resolution and AI table lookup now detect ambiguity and return canonical identities.
  • Documentation
    • Expanded AI package README to document table/schema context behavior and default tools.
  • Style
    • Multiple UI and code formatting refinements across the workspace editor and dashboards.
  • Tests
    • Added/updated tests for scoped table-schema context and canonical dashboard table resolution.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Introduces tableSchemaContext.ts and tableIdentity.ts modules for LLM-ready table schema context with scope filtering, budget-aware formatting, and canonical table ID resolution. Refactors defaultInstructions.ts to delegate to these and gains new tool-usage rules. Extends mosaic dashboard agent with table ID-aware resolution, widens tool return types, and enhances prompts with column types. Abstracts chart data-source references via getChartTableReference. Updates CLI app table and tool initialization. Adds comprehensive test coverage. Applies widespread cosmetic code reformatting across all packages.

Changes

Table identity and schema context for AI tools

Layer / File(s) Summary
Table identity resolution and matching helpers
packages/ai/src/tools/tables/tableIdentity.ts, packages/ai/__tests__/tableTools.test.ts
New module defines TableIdentitySummary containing canonical fully-quoted tableId, database/schema/table names, view flag, column counts. Implements getCanonicalTableId from table.table.toString(), getAllTablesFromSchemaTrees tree traversal, createTableIdentitySummary factory. Exports resolveTableFromCatalog matching (canonical first, then parsed qualified names, then bare names) with ambiguity detection and formatAmbiguousTableMessage for error messaging. Test suite validates identity summary generation, unique/ambiguous bare-name resolution, canonical-match precedence, and tree extraction.
Table schema context types, scope filtering, and formatting
packages/ai/src/tools/tableSchemaContext.ts
New 400-line module defines TableSchemaContextLimits, AiTableScope, AiTableScopeOptions, DEFAULT_TABLE_SCHEMA_CONTEXT_LIMITS. Implements getAiTableSchemaContextLimits, getTablesForAiScope scope membership filtering with main/current_database/all options, getAiTableScopeSummary for outside-main table grouping. Exports AI-oriented naming helpers (getTableIdForAi, getDatabaseNameForAi, getSchemaNameForAi, getFullTableNameForAi with proper SQL quoting). Provides rendering: formatTableSchemaForAi (row counts, column types, comments), formatTableSummaryForAi (concise line with tableId), formatOtherTableScopesForAi (grouped locations). Main entry point formatTablesForLLM selects full-schema vs. hybrid strategy, applies character-budget truncation, handles omitted-table messaging.
defaultInstructions refactoring and enhanced tool rules
packages/ai/src/tools/defaultInstructions.ts
Removes local formatTablesForLLM implementation, re-exports from tableSchemaContext. Adds DEFAULT_INSTRUCTIONS rules: call read_table_schema before writing SQL on unknown-column tables, resolve bare table names to canonical tableId before tool execution, use list_tables to search/page when referenced tables aren't shown. Tightens "Available tables" section description to explicitly reference the main schema format.
List/read table tools refactored to use table identity helpers
packages/ai/src/tools/tables/listTables.ts, packages/ai/src/tools/tables/readTableSchema.ts
listTables.ts changes TableSummary from local shape to TableIdentitySummary alias; builds output via createTableIdentitySummary. readTableSchema.ts replaces direct schema-tree lookup with resolveTableFromCatalog for ambiguity detection; explicit error handling via formatAmbiguousTableMessage; sets response table.id using getCanonicalTableId.
DuckDB quoting and table reference utilities
packages/duckdb-core/src/duckdb-utils.ts, packages/duckdb-core/src/index.ts, packages/duckdb/src/index.ts, packages/duckdb-core/__tests__/getUnqualifiedSqlIdentifier.test.ts, packages/duckdb-core/README.md, packages/duckdb/README.md
New quoteTableReference(tableName): string function parses SQL table references and returns fully-qualified, properly-escaped double-quoted forms. Handles bare names, qualified identifiers, and preserves dots within quoted segments without accidental double-quoting. Exported from core and duckdb barrel entries. Test suite validates behavior. README examples demonstrate usage alongside makeQualifiedTableName.
Mosaic dashboard agent: canonical table ID resolution and column types
packages/mosaic/src/ai/ai.ts, packages/mosaic/src/charts/chart-types/base-types.ts
DashboardAiTable extended with qualifiedName: QualifiedTableName. Dashboard agent adds ID-aware table resolution helpers (resolveDashboardTable, getResolvedTable), normalizes resolved table/column typing with {name, type}[] metadata, updates resolveTable to return canonical IDs and column types, buildAgentPrompt formats Columns: name (type) and appends table ID context, validateTableExists throws on ambiguity. Agent metadata records resolved canonical table names. ResolvedTable interface adds qualifiedName?: QualifiedTableName. resolveTable contract accepts string | QualifiedTableName.
Chart table reference abstraction and application
packages/mosaic/src/charts/chart-types/base-types.ts, packages/mosaic/src/charts/chart-types/count-plot/spec.ts, packages/mosaic/src/charts/chart-types/custom-spec/spec.ts, packages/mosaic/src/charts/chart-types/heatmap/spec.ts, packages/mosaic/src/charts/chart-types/histogram/spec.ts, packages/mosaic/src/charts/chart-types/line-chart/spec.ts, packages/mosaic/src/charts/chart-types/scatter-plot/spec.ts, packages/mosaic/src/charts/MosaicChartView.tsx, packages/mosaic/src/charts/useChartDataPolicy.tsx
Introduces getChartTableReference(dataTable): string helper returning dataTable.table.toString(). All chart specs (count-plot, custom-spec, heatmap, histogram, line-chart, scatter-plot) now use centralized reference instead of dataTable.table.table. MosaicChartView and useChartDataPolicy adopt the abstraction for consistent table reference handling. Chart test verifies spec uses qualified table reference in data sources.
CLI app: adopt scope filtering and full default tools
apps/sqlrooms-cli-ui/src/createDashboardAgent.ts, apps/sqlrooms-cli-ui/src/createDashboardToolDeps.ts
createDashboardAgent returns createDefaultAiTools(store, { query: {}, commands: false }) directly. createDashboardToolDeps imports getTablesForAiScope and getTableIdForAi; calls getTablesForAiScope(..., { scope: 'all' }); derives table identity fields using canonical helpers instead of direct property access.
Test suites for table identity, schema context, and dashboard agent
packages/ai/__tests__/tableSchemaContext.test.ts, packages/mosaic/__tests__/dashboard-ai.test.ts, packages/mosaic/__tests__/chart-types/line-chart-spec.test.ts
tableSchemaContext.test.ts covers database filtering, main/all scoping, hybrid output with column types and fully-qualified tableId, additional-table messaging, maxChars truncation. dashboard-ai.test.ts validates resolveTable canonical ID matching, display-name resolution across call patterns, qualifiedName-only derivation, ambiguous rejection messaging with canonical IDs. Async test verifies createDashboardAgentTool includes Table ID for tool calls: in prompt. Line-chart spec test uses DataTable mock with qualified toString() and asserts spec uses it.
Package exports, Jest config, and documentation
packages/ai/src/index.ts, packages/ai/jest.config.js, packages/ai/package.json, packages/ai/README.md
index.ts re-exports 12 values and 3 types from tableSchemaContext. jest.config.js spreads preset with ts-jest annotation. package.json adds test/test:watch scripts, @sqlrooms/duckdb-core dependency, ts-jest@^29.4.4. README.md documents createDefaultAiTools, createQueryTool, hybrid DuckDB table context, default tool registration, scope/schema/database parameter effects.

Widespread code formatting and layout adjustments

Layer / File(s) Summary
CliWorkspaceTopbar layout and CSS constraint updates
apps/sqlrooms-cli-ui/src/workspace/CliWorkspaceTopbar.tsx
Room title wrapper changes from min-w-0 max-w... to centered layout with max-w-[min(48rem,58vw)]. Artifact title changes to max-w-[20rem] min-w-0. Store selectors and imports reformatted.
CLI UI, SQL editor, AI, artifacts, documents, UI, mosaic, and pivot formatting
apps/sqlrooms-cli-ui/src/components/*, packages/ai-core/src/components/Chat.tsx, packages/artifacts/src/ai/*, packages/blocks/src/index.ts, packages/documents/src/..., packages/sql-editor/src/..., packages/ui/src/components/tree.tsx, packages/mosaic/src/ai.ts, packages/pivot/...
Pure whitespace and line-wrap reformats: import line-wrapping, function signature multi-line formatting, expression collapsing, Tailwind class reordering, JSX attribute rewrapping. No behavioral or API changes except topbar max-width layout modification.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI createDashboardAgent
    participant Agent as ToolLoopAgent
    participant Resolve as Dashboard resolveTable
    participant Instr as createDefaultAiInstructions
    participant Format as formatTablesForLLM

    CLI->>Agent: createQueryTools() → createDefaultAiTools(..., {query:{}, commands:false})
    Agent->>Resolve: resolveTable(dashboardId, tableName)
    Resolve->>Resolve: resolveDashboardTable(match by id/qname/name)
    Resolve->>Resolve: getResolvedTable(with column types)
    Resolve-->>Agent: resolved table + column metadata
    Agent->>Instr: createDefaultAiInstructions(tables, currentDatabase)
    Instr->>Format: formatTablesForLLM(tables, currentDatabase, limits)
    Format->>Format: getTablesForAiScope(filter by scope)
    Format->>Format: formatTableSchemaForAi / formatTableSummaryForAi
    Format->>Format: Budget-aware hybrid builder (full→summary→count)
    Format-->>Instr: formatted table context string
    Instr-->>Agent: DEFAULT_INSTRUCTIONS + context
    Agent->>Agent: tools: {query, list_tables, read_table_schema, ...extra}
    Agent-->>CLI: agent ready with all tools
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~70 minutes

Possibly related PRs

  • sqlrooms/sqlrooms#634: Both PRs modify dashboard agent tooling wiring in createDashboardAgent.ts and createDashboardToolDeps.ts to change table resolution and tool exposure to the agent.
  • sqlrooms/sqlrooms#650: Both PRs refactor dashboard AI tool dependencies and table resolution in createDashboardToolDeps.ts, with the main PR adding scope filtering and canonical table ID logic.
  • sqlrooms/sqlrooms#699: The main PR's AssistantChatContainer.tsx change reformats the same createSessionDisabled boolean condition area.

Suggested reviewers

  • dmitriy-kostianetskiy

🐇 New tables dance with canonical IDs,
Schema context trimmed, no more bits hid.
Chart references gleam through every spec,
Dashboard agents resolve with proper checks.
Formatters hop through code near and far—
A codebase more tidy, like a shining star! ⭐

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tableSchema-tools

ilyabo added 2 commits June 17, 2026 13:05
# Conflicts:
#	packages/ai/src/tools/defaultTools.ts
#	packages/mosaic/src/ai.ts
@ilyabo
ilyabo marked this pull request as ready for review June 17, 2026 12:17
@ilyabo
ilyabo requested a review from lixun910 June 17, 2026 12:17

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 10d47f9b83

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/ai/src/tools/tableSchemaContext.ts Outdated
Comment thread packages/ai/src/tools/tableSchemaContext.ts Outdated

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/ai/package.json (1)

18-26: ⚠️ Potential issue | 🟠 Major

Add missing ts-jest dependency to align with monorepo patterns and resolve knip validation.

All 20+ packages using @sqlrooms/preset-jest declare ts-jest in devDependencies. packages/ai is missing this declaration while still using the preset-jest configuration, which causes knip to flag an unresolved dependency. Add ts-jest to devDependencies to match the established pattern:

Manifest fix
   "scripts": {
     "build": "tsc",
     "dev": "tsc -w",
     "lint": "eslint .",
     "test": "jest",
     "test:watch": "jest --watch",
     "typecheck": "tsc --noEmit",
     "typedoc": "typedoc"
   },
+  "devDependencies": {
+    "ts-jest": "^29.4.4"
+  },
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ai/package.json` around lines 18 - 26, The packages/ai package.json
file is missing the ts-jest devDependency despite using the
`@sqlrooms/preset-jest` configuration, which causes knip validation to fail. Add
ts-jest to the devDependencies section of packages/ai/package.json to match the
established pattern used consistently across 20+ other packages in the monorepo
that also use the preset-jest configuration.

Source: Pipeline failures

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/sqlrooms-cli-ui/src/createDashboardToolDeps.ts`:
- Line 34: The tableName assignment on line 34 uses a fallback pattern that can
lose fully-qualified table identity and cause the agent to select the wrong
table when multiple databases have tables with identical names. Remove the
fallback logic and use table.tableName directly as the stable unique identifier
for internal routing. If a user-friendly display label is needed, derive it
separately rather than using it for internal agent selection.

In `@packages/ai/__tests__/tableSchemaContext.test.ts`:
- Around line 33-41: The test "does not filter by database when currentDatabase
is unavailable" is actually testing schema filtering rather than database
filtering behavior. The test creates two tables where one has schema 'analytics'
which causes it to be filtered out - but this proves schema filtering is
happening, not that database filtering is absent. To fix this test and prove
that database filtering is not happening when currentDatabase is unavailable,
create two tables that differ only in their database property (both with the
same or no schema), then assert that both tables are included in the
formatTablesForLLM output, demonstrating that the database values are not used
for filtering.

---

Outside diff comments:
In `@packages/ai/package.json`:
- Around line 18-26: The packages/ai package.json file is missing the ts-jest
devDependency despite using the `@sqlrooms/preset-jest` configuration, which
causes knip validation to fail. Add ts-jest to the devDependencies section of
packages/ai/package.json to match the established pattern used consistently
across 20+ other packages in the monorepo that also use the preset-jest
configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6445c543-6e4c-4d48-9dd1-ad2b12af75a2

📥 Commits

Reviewing files that changed from the base of the PR and between dde7e27 and 10d47f9.

📒 Files selected for processing (32)
  • apps/sqlrooms-cli-ui/src/components/AssistantChatContainer.tsx
  • apps/sqlrooms-cli-ui/src/components/useLocalFileLoader.ts
  • apps/sqlrooms-cli-ui/src/createDashboardAgent.ts
  • apps/sqlrooms-cli-ui/src/createDashboardToolDeps.ts
  • apps/sqlrooms-cli-ui/src/workspace/ArtifactsContainerPanel.tsx
  • apps/sqlrooms-cli-ui/src/workspace/CliWorkspaceTopbar.tsx
  • apps/sqlrooms-cli-ui/src/workspace/WorksheetSqlQueryBlockRenderer.tsx
  • packages/ai-core/src/components/Chat.tsx
  • packages/ai/README.md
  • packages/ai/__tests__/tableSchemaContext.test.ts
  • packages/ai/jest.config.js
  • packages/ai/package.json
  • packages/ai/src/index.ts
  • packages/ai/src/tools/defaultInstructions.ts
  • packages/ai/src/tools/tableSchemaContext.ts
  • packages/artifacts/src/ai/artifactAiSessionHelpers.ts
  • packages/artifacts/src/ai/artifactContextTools.ts
  • packages/blocks/src/index.ts
  • packages/documents/README.md
  • packages/documents/src/BlockDocumentEditor/BlockDocumentBlockControls.tsx
  • packages/documents/src/MarkdownDocumentEditor/MarkdownDocumentEditorRoot.tsx
  • packages/mosaic/src/ai.ts
  • packages/mosaic/src/ai/ai.ts
  • packages/pivot/README.md
  • packages/pivot/src/PivotBlock.tsx
  • packages/sql-editor/src/SqlEditorSlice.tsx
  • packages/sql-editor/src/SqlQueryBlock.tsx
  • packages/sql-editor/src/codemirror/extensions/completion.ts
  • packages/sql-editor/src/codemirror/utils/schema-converter.ts
  • packages/sql-editor/src/components/QueryEditorPanelActions.tsx
  • packages/sql-editor/src/components/QueryResultPanel.tsx
  • packages/ui/src/components/tree.tsx

Comment thread apps/sqlrooms-cli-ui/src/createDashboardToolDeps.ts Outdated
Comment thread packages/ai/__tests__/tableSchemaContext.test.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bfc788ccd3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/sqlrooms-cli-ui/src/createDashboardToolDeps.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e3e1d8a47e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +32 to +34
getTablesForAiScope(state.db.tables, state.db.currentDatabase, {
scope: 'main',
}).map((table) => ({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't hide attached tables from dashboard AI

When a room has visible tables outside the current database's main schema (for example an attached DuckDB/MotherDuck database or another schema), this filter removes them from the dashboard adapter even though the dashboard tools validate table names only against adapter.getTables() before creating panels. In that scenario list_tables can still discover the table, but dashboard_agent/chart tools will report it as unknown instead of building the requested dashboard, which regresses the previous behavior that exposed all state.db.tables.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5840ad6e9d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/sqlrooms-cli-ui/src/createDashboardToolDeps.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 94aa86d08a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/mosaic/src/charts/MosaicChartView.tsx

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ai/src/tools/tables/tableIdentity.ts`:
- Around line 31-33: The condition in the `getAllTablesFromSchemaTrees` function
currently only includes nodes where `tableNode?.object?.type === 'table'`, but
it should also include nodes where the type is 'view' since both `list_tables`
and `read_table_schema` depend on this helper to access views from the schema
tree. Modify the condition to check for both 'table' and 'view' types by
updating the type comparison to accept either value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a24f0285-a8aa-4625-91bd-bcabbf756535

📥 Commits

Reviewing files that changed from the base of the PR and between 5840ad6 and 94aa86d.

📒 Files selected for processing (20)
  • apps/sqlrooms-cli-ui/src/createDashboardToolDeps.ts
  • packages/ai/__tests__/tableSchemaContext.test.ts
  • packages/ai/__tests__/tableTools.test.ts
  • packages/ai/src/tools/defaultInstructions.ts
  • packages/ai/src/tools/tableSchemaContext.ts
  • packages/ai/src/tools/tables/listTables.ts
  • packages/ai/src/tools/tables/readTableSchema.ts
  • packages/ai/src/tools/tables/tableIdentity.ts
  • packages/mosaic/__tests__/chart-types/line-chart-spec.test.ts
  • packages/mosaic/__tests__/dashboard-ai.test.ts
  • packages/mosaic/src/ai/ai.ts
  • packages/mosaic/src/charts/MosaicChartView.tsx
  • packages/mosaic/src/charts/chart-types/base-types.ts
  • packages/mosaic/src/charts/chart-types/count-plot/spec.ts
  • packages/mosaic/src/charts/chart-types/custom-spec/spec.ts
  • packages/mosaic/src/charts/chart-types/heatmap/spec.ts
  • packages/mosaic/src/charts/chart-types/histogram/spec.ts
  • packages/mosaic/src/charts/chart-types/line-chart/spec.ts
  • packages/mosaic/src/charts/chart-types/scatter-plot/spec.ts
  • packages/mosaic/src/charts/useChartDataPolicy.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/ai/tests/tableSchemaContext.test.ts
  • apps/sqlrooms-cli-ui/src/createDashboardToolDeps.ts
  • packages/ai/src/tools/tableSchemaContext.ts

Comment thread packages/ai/src/tools/tables/tableIdentity.ts Outdated
@ilyabo ilyabo changed the title feat: Improving tableSchema tools feat: Improving tableSchema AI tools Jun 17, 2026
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/ai/src/tools/tables/tableIdentity.ts (1)

21-114: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add JSDoc documentation for public exports.

The exported functions lack documentation. As per coding guidelines, "Public exports in packages/ should be kept generic, composable, documented, and free of app/example-specific assumptions." Adding JSDoc comments for getCanonicalTableId, getAllTablesFromSchemaTrees, createTableIdentitySummary, resolveTableFromCatalog, and formatAmbiguousTableMessage would help consumers understand the API and align with project standards.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ai/src/tools/tables/tableIdentity.ts` around lines 21 - 114, Add
JSDoc documentation comments to all five exported functions in the tableIdentity
file: getCanonicalTableId, getAllTablesFromSchemaTrees,
createTableIdentitySummary, resolveTableFromCatalog, and
formatAmbiguousTableMessage. Each JSDoc should include a clear description of
what the function does, parameter documentation with types, and return value
documentation. This will provide API consumers with clear understanding of each
function's purpose and usage.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/ai/src/tools/tables/tableIdentity.ts`:
- Around line 21-114: Add JSDoc documentation comments to all five exported
functions in the tableIdentity file: getCanonicalTableId,
getAllTablesFromSchemaTrees, createTableIdentitySummary,
resolveTableFromCatalog, and formatAmbiguousTableMessage. Each JSDoc should
include a clear description of what the function does, parameter documentation
with types, and return value documentation. This will provide API consumers with
clear understanding of each function's purpose and usage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d6f2eba6-53e0-42dc-9972-cf4916c2e4c0

📥 Commits

Reviewing files that changed from the base of the PR and between 94aa86d and f737bc7.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (16)
  • apps/sqlrooms-cli-ui/src/createDashboardToolDeps.ts
  • packages/ai/__tests__/tableTools.test.ts
  • packages/ai/jest.config.js
  • packages/ai/package.json
  • packages/ai/src/tools/tables/tableIdentity.ts
  • packages/duckdb-core/README.md
  • packages/duckdb-core/__tests__/getUnqualifiedSqlIdentifier.test.ts
  • packages/duckdb-core/src/duckdb-utils.ts
  • packages/duckdb-core/src/index.ts
  • packages/duckdb/README.md
  • packages/duckdb/src/index.ts
  • packages/mosaic/__tests__/BoxPlotClient.test.ts
  • packages/mosaic/__tests__/dashboard-ai.test.ts
  • packages/mosaic/src/ai/ai.ts
  • packages/mosaic/src/charts/chart-types/base-types.ts
  • packages/mosaic/src/charts/chart-types/box-plot/renderer/BoxPlotClient.ts
💤 Files with no reviewable changes (1)
  • apps/sqlrooms-cli-ui/src/createDashboardToolDeps.ts
✅ Files skipped from review due to trivial changes (2)
  • packages/duckdb/README.md
  • packages/duckdb-core/README.md
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/mosaic/src/charts/chart-types/base-types.ts
  • packages/ai/jest.config.js
  • packages/ai/tests/tableTools.test.ts
  • packages/ai/package.json
  • packages/mosaic/tests/dashboard-ai.test.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a31db85e65

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

adapter.setSelectedTable(state, artifactId, explicitTableName);
return {tableName: explicitTableName, columns};
const resolvedTable = getResolvedTable(table);
adapter.setSelectedTable(state, artifactId, resolvedTable.tableName);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid double-quoting map table IDs

When a dashboard tool resolves an explicit table, this now stores the fully quoted tableId in dashboard.selectedTable. Deck map datasets that omit dataset.source fall back to that selected table (packages/deck/src/dashboardConfig.ts:99-106), and map auto-fit still builds bounds SQL by doing source.tableName.split('.').map(escapeId) (packages/deck/src/dashboard.tsx:192-196), so a selected table like "local"."main"."events" becomes """local"""."""main"""."""events""" and fit-to-data queries fail for those AI-created maps. Update the deck map table-reference handling before storing/forwarding quoted ids here.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acefdbb9c3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +242 to +244
const bareMatches = tables.filter(
(candidate) => candidate.table.table === trimmedTableReference,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve quoted bare table references

When the caller passes a quoted bare SQL identifier such as "events.2026" for a unique table whose name contains a dot, parseQualifiedSqlIdentifier correctly strips it to events.2026, but this branch only uses parsed identifiers when a schema/database is present and then compares against the original quoted string. That makes resolveTableReference return not found for quoted bare names, which breaks read_table_schema/dashboard resolution unless the caller supplies the fully qualified tableId.

Useful? React with 👍 / 👎.

@ilyabo
ilyabo merged commit 1948bfd into main Jun 17, 2026
3 checks passed
@ilyabo
ilyabo deleted the tableSchema-tools branch June 17, 2026 19:04
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.

1 participant