Skip to content

fix: surface project context in system prompt for connection discovery#278

Closed
suryaiyer95 wants to merge 2 commits intomainfrom
fix/use-dbt-connection
Closed

fix: surface project context in system prompt for connection discovery#278
suryaiyer95 wants to merge 2 commits intomainfrom
fix/use-dbt-connection

Conversation

@suryaiyer95
Copy link
Contributor

Summary

  • Injects a <project-context> block into the system prompt based on workspace fingerprint detection
  • dbt project open: instructs the LLM to try dbt connection first (via profiles.yml), fall back to a configured warehouse connection, and ask the user for credentials (scoped to the detected adapter) if both fail
  • No dbt project: instructs the LLM to check for an existing warehouse connection and ask the user for adapter-appropriate credentials if none is configured
  • Detected warehouse adapter (e.g. snowflake, bigquery) is surfaced in both paths so credential prompts are specific, not generic

Motivation

Previously the agent had no awareness of the open project's connection context. It would either silently fail or ask for generic credentials. This change makes the agent behave like it understands the environment — trying the right path first and asking the right questions when things don't work.

Test plan

  • Open a dbt project with a valid profiles.yml — agent should use dbt connection without asking for credentials
  • Open a dbt project where dbt connection fails — agent should fall back to warehouse connection or ask for credentials with the correct adapter type
  • Open a non-dbt project with a detected adapter (e.g. .sqlfluff + snowflake) — agent should ask for warehouse credentials scoped to that adapter
  • Open a project with no detectable tags — <project-context> block should be omitted entirely

🤖 Generated with Claude Code

Inject a `<project-context>` block into the system prompt based on the
workspace fingerprint, so the LLM agent knows how to handle SQL connections
appropriately for the open project.

- dbt project detected: try dbt connection first (profiles.yml), fall back
  to configured warehouse, then ask user for credentials — with the detected
  adapter type (e.g. snowflake, bigquery) pre-filled in the prompt
- No dbt project: check for existing warehouse connection, ask user for
  adapter-scoped credentials if none is configured

The LLM is explicitly told not to assume the dbt connection will succeed,
ensuring graceful fallback and correct credential prompting when it fails.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 18, 2026 20:53
Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the session system prompt by injecting a <project-context> block derived from workspace fingerprinting so the agent can make better, adapter-specific decisions when discovering SQL/dbt/warehouse connections.

Changes:

  • Build the environment system prompt as an array (parts) and optionally append a <project-context> section.
  • Detect workspace tags (including dbt + warehouse adapter) and add connection-discovery guidance to the system prompt based on those tags.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

…drift

- Wrap fingerprint detection in try/catch so a failure never blocks
  session startup (addresses Sentry MEDIUM bug report)
- Call `Fingerprint.detect()` directly instead of `get() ?? detect()`:
  `detect()` already caches per-cwd, so this is equivalent but avoids
  injecting stale tags when the cwd changes (addresses Copilot comment)
- Export `ADAPTER_TAGS` from fingerprint module as the single source of
  truth; reuse it in both `detectDir` (replacing the hardcoded regex) and
  the system prompt builder — fixes the missing `sqlite` and prevents
  future drift (addresses Copilot comment)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants