AI-assisted workflows
AI-assisted workflows help engineers understand, create, and improve Bruin data work. They connect local asset files and project data to approved AI tools, while keeping the result inside normal Bruin validation, pipeline execution, and connection rules.
Workflow model
AI work in Bruin follows three related paths. An engineer can enrich an existing asset with bruin ai enhance, install guidance for an external agent with bruin ai skills, or expose an AI task as a pipeline asset. Bruin MCP adds a fourth path for assistants that need to query data or build pipelines through Bruin.
Asset enhancement
The ai enhance workflow adds context to an existing asset rather than creating a new pipeline from nothing. It gives the selected AI provider the asset and pipeline context, and it can add missing column information and table statistics before asking the provider to suggest descriptions, tags, quality checks, and other metadata. The command then formats and validates the changed asset. If validation fails, it restores the original file. docs/…/ai-enhance.md, cmd/enhance.go
The workflow accepts one asset or a folder of assets. A folder can process several assets in parallel, while JSON output supports automation. Existing metadata is preserved by the enhancement instructions, so the result is an additive catalog update that still needs normal engineering review.
When an engineer asks an AI assistant to build a new pipeline, the workflow is different. Bruin MCP gives the assistant access to Bruin commands and documentation so it can inspect sources, define assets, query data, and validate the result. The assistant remains the author of the proposed pipeline; Bruin supplies the data and execution boundary. docs/…/bruin-mcp.md
The main enhancement sequence is shown below.
flowchart LR
A[Asset or asset folder] --> B[Load project environment]
B --> C[Fill schema context]
C --> D[AI provider edits metadata]
D --> E[Format asset]
E --> F{Bruin validation}
F -->|Pass| G[Keep enhanced asset]
F -->|Fail| H[Restore original asset]
References: docs/…/ai-enhance.md• L45-105 cmd/enhance.go• L96-123 cmd/enhance.go• L489-549 pkg/…/enhancer.go• L75-115
Agent skill provisioning
The ai skills workflow installs reusable instructions for AI agents in a project. It can install one skill, all bundled skills, or repository-level AGENTS.md guidance. The install location is chosen from .agents and .claude, with .agents/skills as the shared home when both agent environments are present. docs/…/ai-skills.md, cmd/skills.go
Skills turn general AI access into a task-specific workflow. The bundled skills cover semantic-layer work and common pipeline investigations such as failures, schema drift, duplicates, freshness, and quality checks. A skill can declare required project connections, which lets installation ask before it adds placeholder Bruin Cloud or GitHub connections. docs/…/ai-skills.md, skills/…/SKILL.md
References: docs/…/ai-skills.md• L3-16 docs/…/ai-skills.md• L27-60 cmd/skills.go• L36-52 cmd/skills.go• L238-306
Pipeline agent assets
An agent.claude_code asset makes an AI task part of a scheduled or manually run pipeline. Its prompt can use run context such as dates, pipeline name, and run ID. The task can analyze data, generate code or reports, and return text or JSON through the Claude Code command-line tool. It is a pipeline task, but it does not need a warehouse connection to start because the prompt and agent tools define its work. examples/…/README.md, examples/…/data_analysis_agent.asset.yml
The agent asset validates its prompt and runtime controls before execution. It can limit directories and tools, select a model, choose an output format, and continue a session. Bruin renders prompt templates before it starts the external agent, which lets one asset produce run-specific work.
References: pkg/…/pipeline.go• L29-42 pkg/…/operator.go• L112-175 pkg/…/operator.go• L252-380 examples/…/data_analysis_agent.asset.yml• L1-25
Connection model
AI workflows use the same project connection and environment model as other Bruin commands. Credentials stay outside prompts and source code when the project uses environment references or a configured secrets backend. See Platform services for the wider service model, Secrets management for shared secret resolution rules, and Bruin Cloud integration for the managed service connection.
AI connection types
Project configuration supports dedicated connection types for the AI tools and services that Bruin workflows use. Each connection has a name and a sensitive credential field. GitHub also carries the repository owner and name so an agent skill can work against the intended repository. pkg/…/manager.go, pkg/…/connections.go, pkg/…/connections.go
The skill installer checks all environments before adding a required connection. It does not add a duplicate type when a matching connection already exists. When it adds a placeholder, it uses ${BRUIN_CLOUD_API_TOKEN} for Bruin Cloud and ${GITHUB_TOKEN} for GitHub. GitHub owner and repository values come from the local Git remote when that information is available. cmd/ai_connections.go, cmd/ai_connections.go
References: pkg/…/manager.go• L45-79 pkg/…/connections.go• L838-845 pkg/…/connections.go• L1230-1239 pkg/…/connections.go• L2074-2080 cmd/ai_connections.go• L43-87 cmd/ai_connections.go• L122-190
Provider selection
Asset enhancement treats each supported AI tool as a provider behind one common workflow. Claude Code is the default. OpenCode, Codex, and Cursor can be selected with a provider flag, and an optional model name changes the model used by that tool. Only one provider can be selected for an enhancement run. cmd/enhance.go, cmd/enhance.go
The provider boundary also normalizes user feedback. Each CLI can stream its own event format, while Bruin turns tool activity, completion, and error events into readable progress. Authentication remains provider-specific: Claude and Cursor can receive a key through an environment variable, while OpenCode and Codex use their native sign-in flow. pkg/…/provider.go, pkg/…/provider_factory.go, pkg/…/provider_factory.go
| Provider | Bruin selection | Default or native model behavior | Authentication path |
|---|---|---|---|
| Claude Code | Default or --claude | claude-sonnet-4-20250514 by default | ANTHROPIC_API_KEY or Claude sign-in |
| OpenCode | --opencode | anthropic/claude-sonnet-4-20250514 by default | OpenCode native auth |
| Codex | --codex | Uses the Codex CLI default unless a model is set | Codex native auth after login |
| Cursor | --cursor | Uses the Cursor CLI default unless a model is set | CURSOR_API_KEY |
References: cmd/enhance.go• L48-85 cmd/enhance.go• L434-487 pkg/…/provider_factory.go• L7-41 pkg/…/provider_factory.go• L43-152 pkg/…/provider_cli.go• L115-191
Python parsing bridge
The repository uses an embedded Python parser as a shared SQL analysis service. It is separate from the external AI providers. Its purpose is to give Bruin a stable way to inspect SQL across warehouse dialects and to prepare safe query forms for lineage and tests.
SQL analysis role
The parser identifies used tables and column lineage from SQL plus a schema description. It also performs structural query changes that other Bruin workflows need, such as renaming table references, adding limits or common table expressions, selecting an intermediate CTE, extracting the read-only SELECT inside DDL, and freezing time-dependent expressions. These results help Bruin reason about assets without sending SQL execution control to an AI provider. pkg/…/parser.go, pkg/…/parser.go, pkg/…/parser.go
The Python side uses SQLGlot to parse dialect-aware statements. It returns structured JSON for tables, columns, upstream sources, and parse errors. The service skips column lineage for queries over the configured length limit and reports that condition instead of trying to process an unbounded query. SQL formatting uses the same managed Python tool path and supplies the SQL dialect and project template context before it changes a file. pythonsrc/…/main.py, pythonsrc/…/main.py, pkg/…/parser.go, pkg/…/uv.go, pkg/…/uv.go
References: pkg/…/parser.go• L150-235 pkg/…/parser.go• L263-289 pkg/…/parser.go• L422-465 pythonsrc/…/main.py• L248-294 pkg/…/uv.go• L842-929 pkg/…/uv.go• L1034-1101
Embedded Python runtime
Bruin packages the Python parser source with the application so normal CLI use does not depend on a separately checked-out parser project. At startup, the Go side extracts the embedded Python runtime, SQLGlot files, and parser source to managed temporary paths, then starts a long-lived JSON-line process. Go sends one command at a time and reads one JSON response at a time. pythonsrc/embed.go, pkg/…/parser.go, pkg/…/parser.go
The process accepts a small command set that keeps the Go and Python sides decoupled. The command names and JSON fields are a shared contract, so changes to one side must update the other side at the same time.
References: pythonsrc/embed.go• L1-8 pythonsrc/main.py• L30-100 pkg/…/parser.go• L68-143 pkg/…/parser.go• L271-289
Python asset execution
Python assets run in an isolated environment managed by uv. The runner supports Python 3.8 through 3.14 and uses 3.11 by default. An asset image can choose a supported version, while a project's requires-python rule selects the lowest available version that satisfies its constraints. pkg/…/uv.go, pkg/…/uv.go, pkg/…/uv.go
The runner uses the project's pyproject.toml dependency context when present. It locks those dependencies before execution and treats the directory that owns the project file as the Python project root. This also applies to table materialization, so the generated Arrow wrapper runs from that project root and uses the project dependencies instead of switching to an isolated script environment. When that file is absent, it can use a requirements file or run without extra project dependencies. pkg/…/uv.go, pkg/…/uv.go
An asset without table materialization returns its result to the normal task flow. A table asset writes supported Python results to an Arrow file, then loads that data into the destination through the same ingestion path used by other pipeline data. The runner supports data frames, Arrow tables, row lists, and streamed batches. It keeps one Arrow schema across streamed output so a Python asset can process large results without holding the full data set in memory. pkg/…/uv.go, pkg/…/uv.go
Table assets pass their Bruin materialization strategy to ingestr before the destination load. Python assets support replace, append, merge, and delete-and-insert strategies. ingestr also accepts truncate-and-insert for regular destinations. Update and delete are reserved for reverse-ETL destinations, which currently include Attio, CleverTap, HubSpot, and Salesforce. These API destinations accept only the strategies defined for each service and do not support a full refresh. pkg/…/materialization_mapping.go, pkg/…/materialization_mapping.go, pkg/…/materialization_mapping.go
The same runtime boundary starts ingestr for data loading. The current default is released ingestr v1.1.92, which runs as a standalone binary; local source versions and legacy v0 releases continue through uv. This keeps normal runs independent of a Python package checkout without removing local development support. For a URI that targets Quack, the runner puts the pinned DuckDB 2.0.0 driver path before the standard driver path. Other URIs keep the standard path, so the Quack driver does not replace the driver used by other DuckDB services. Long-running ingestion runs can be tied to the execution context so cancellation can stop the child process cleanly. pkg/…/uv.go, pkg/…/uv.go, pkg/…/uv.go, pkg/…/config.go, pkg/…/lock.go
The Python ingestion boundary also checks change-data-capture (CDC) snapshot settings before ingestr performs checks that need database access. Automatic snapshots can run with CDC, while a no-snapshot mode requires a named slot and explicit source tables. A starting PostgreSQL log sequence number (LSN) is allowed only in no-snapshot mode, and that mode cannot run with a full refresh. pkg/…/cdc.go
Chunked CDC snapshots provide a separate mode for copying a complete source table in smaller pieces while changes continue to collect. The mode requires CDC and merge behavior. It supports serial or parallel snapshot work and can keep pending write-ahead-log data in memory or stage it at the destination. Its validation rejects combinations that would change the complete-table boundary, such as extraction filters, a starting LSN, a non-merge strategy, or a disabled snapshot. During a chunked snapshot, the runner omits scheduler interval bounds so those bounds cannot cut the complete copy into an incomplete result. pkg/…/cdc_chunked.go, pkg/…/helper.go
Destination selection follows the connection used by the asset. An ingestr asset fills a missing destination from its destination connection, while an inference asset always derives the destination from its own connection so quality checks cannot be routed to a conflicting user value. The pipeline caches connection-type lookups during this pass because some secret backends fetch values on every lookup. pkg/…/ingestr_destination.go
For inference-specific behavior, see Inference operations, which describes how those assets use their connection and destination rules.
References: pkg/…/uv.go• L30-50 pkg/…/uv.go• L44-82 pkg/…/uv.go• L125-200 pkg/…/uv.go• L243-349 pkg/…/uv.go• L379-568 pkg/…/uv.go• L570-646 pkg/…/uv.go• L715-868 pkg/…/materialization_mapping.go• L10-23 pkg/…/materialization_mapping.go• L25-54 pkg/…/materialization_mapping.go• L89-140 pkg/…/cdc.go• L11-63 pkg/…/cdc_chunked.go• L22-126 pkg/…/helper.go• L59-119 pkg/…/ingestr_destination.go• L7-109 pkg/…/config.go• L13-24 pkg/…/lock.go• L163-171
Change checklist
When these files or sections are changed, remember to consider these:
- Add a provider in the provider type list, CLI flag validation, provider factory, default model policy, authentication policy, and stream-event parser together.
- Add or rename a skill connection requirement in its front matter, the connection placeholder logic, the project connection schema, and the secrets resolution path.
- Keep the Python command names and JSON payloads aligned between pkg/…/parser.go and pythonsrc/main.py.
- Keep Python version selection, project dependency locking, requirements-file mode, Arrow result handling, and destination loading aligned when changing Python asset execution.
- Keep the Python-to-
ingestrmaterialization strategy maps aligned with the strategies accepted by each destination. Do not expose reverse-ETL-only strategies to ordinary Python table assets. - Keep CDC snapshot validation aligned with
ingestrfor both batch and streaming runs. Preserve the links between CDC mode, slots, source tables, starting LSNs, and full refresh. - Keep chunked CDC validation aligned with the complete-table and merge contract. Preserve the link between chunked mode and omitted scheduler interval bounds.
- Keep connection-type-to-
ingestrdestination inference aligned with both ingestr assets and inference assets. Preserve the rule that inference destinations come from their own connection. - Keep the reverse-ETL destination list and per-destination strategy rules aligned with
ingestrwhen a supported API destination changes. - Keep
ingestrversion selection aligned with its installer path and driver setup. The released v1 path uses standalone binaries, while local and legacy versions useuv; Quack URIs must search the pinned Quack driver before the standard driver path. - Keep SQL dialect detection, SQLFluff formatting, and the Jinja context used for templated SQL aligned when Python tool execution changes.
- Keep a new
agent.claude_codeparameter aligned across parameter extraction, validation, command construction, and the example asset definitions. - When a parser dialect changes, review both asset-type and direct-connection dialect maps because they serve different entry paths.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The selected AI CLI is not installed or cannot be found | Enhancement stops before the asset is changed | Install the selected CLI and let EnsureCLI verify it before the provider runs |
| More than one enhancement provider flag is set | The run is rejected because provider choice is ambiguous | Select one of Claude, OpenCode, Codex, or Cursor |
| The AI writes an invalid asset definition | The enhancement fails and the original file is restored | Bruin formats and validates the result before keeping it |
| The selected environment has an Anthropic connection backed by a secret store with no API key | Claude enhancement cannot authenticate | Add the API key to the named connection or use the provider's supported sign-in path |
| A skill is installed in non-interactive mode without a skill name | Installation stops because there is no selection to apply | Pass a skill name, all, or the AGENTS.md selection |
| A parser command or response no longer matches the Python bridge contract | Lineage or query rewriting fails at process communication or JSON decoding | Update both command dispatchers and their shared fields together |
| A Python asset returns an unsupported value or inconsistent streamed schema | The asset cannot create its Arrow result and the destination load does not start | Return a supported data frame, Arrow table, row collection, or schema-consistent stream |
| A Python asset uses a materialization strategy that its asset type or destination does not support | The destination load is rejected or produces the wrong write behavior | Use a Python-supported strategy and keep reverse-ETL strategies limited to their marked destinations |
| CDC snapshot options are used without CDC, or no-snapshot mode lacks a slot or explicit tables | The asset is rejected before ingestion | Set cdc: true and satisfy the snapshot and source-table rules |
| No-snapshot CDC mode is combined with a full refresh or an invalid starting LSN | The CDC run is rejected before it reaches ingestr | Use a nonzero PostgreSQL LSN only with no-snapshot mode and avoid full refresh |
| Chunked CDC is combined with extraction filters, a starting LSN, non-merge loading, or disabled snapshots | The asset is rejected because the complete-table snapshot contract is no longer safe | Use chunked CDC only with CDC enabled, merge behavior, and no interval or extraction filters |
| Scheduler interval bounds are applied to a chunked CDC snapshot | The snapshot can load only part of the source table | Let chunked CDC omit scheduler interval bounds while it creates the complete snapshot |
| An inference asset has a destination that disagrees with its connection | The quality check can target the wrong warehouse unless the value is removed | Derive the destination from the inference connection after variant rendering |
| A reverse-ETL destination receives a strategy that its service does not accept | ingestr rejects the load or sends an invalid API operation | Check the destination-specific strategy map before selecting the incremental strategy |
| A Quack URI is sent without its pinned DuckDB driver path | ingestr can load an incompatible driver and fail to connect to Quack | Put the Quack driver directory before the standard driver path when the source or destination URI targets Quack |
| A Python asset requires a version that is not available to the runner | The asset stops before its code runs | Use a supported Python version or a requires-python range with an available match |
| A project dependency file cannot be locked | The Python asset stops before its module runs | Keep pyproject.toml metadata and its Python requirement compatible with the supported runtime |
| A project uses a pyproject.toml in a subdirectory but the asset module path is not relative to that project root | The Python module or table materialization wrapper cannot import the asset | Keep the module path and project root aligned when the dependency file is below the repository root |
| A Claude Code asset is used as a child task rather than a main asset | The scheduler rejects the task | Run the agent asset as a main pipeline asset |
Key files
| File | Why to read it |
|---|---|
| cmd/ai.go | Shows the top-level AI command surface and its enhancement and skill branches. |
| cmd/enhance.go | Shows the end-to-end asset enhancement workflow, environment selection, provider choice, and rollback boundary. |
| pkg/…/enhancer.go | Shows the shared provider-to-asset coordination and validation boundary. |
| pkg/…/provider_factory.go | Shows the supported external AI provider integrations and their default model and auth behavior. |
| cmd/skills.go | Shows how skills and agent guidance are selected, installed, updated, and linked. |
| cmd/ai_connections.go | Shows how required Bruin Cloud and GitHub connections are detected and added without duplicate entries. |
| pkg/…/manager.go | Shows where AI-related connection types enter the project connection model. |
| pkg/…/operator.go | Shows how a pipeline agent asset validates prompts and runs Claude Code with run-time controls. |
| pkg/…/parser.go | Shows the Go-facing SQL analysis contract and the embedded Python process lifecycle. |
| pythonsrc/main.py | Shows the command protocol exposed by the Python parser service. |
| pythonsrc/…/main.py | Shows the SQL analysis and query-rewrite capabilities behind that protocol. |
| pkg/…/uv.go | Shows Python version and dependency selection, project-root execution, SQL formatting support, ingestr runtime and driver selection, streaming cancellation, Arrow result handling, and destination loading. |
| pkg/…/config.go | Shows the separate pinned DuckDB driver used for Quack connections. |
| pkg/…/lock.go | Shows how the runner recognizes Quack URIs. |
| pkg/…/cdc.go | Shows the CDC snapshot rules shared by Python-backed batch and streaming ingestion. |
| pkg/…/cdc_chunked.go | Shows the rules for complete-table CDC snapshots that run in chunks and require merge behavior. |
| pkg/…/helper.go | Shows how asset parameters become ingestr options and why chunked CDC does not receive scheduler interval bounds. |
| pkg/…/ingestr_destination.go | Shows how connection types select ingestr destinations for ingestion and inference assets. |
| pkg/…/materialization_mapping.go | Shows the materialization strategies available to Python assets, regular ingestr loads, and reverse-ETL destinations. |
| docs/…/bruin-mcp.md | Explains how external assistants use Bruin to analyze data and create pipeline work. |
| docs/…/ai-enhance.md | Describes the user-facing enhancement workflow and provider options. |
| docs/…/ai-skills.md | Describes the user-facing skill installation workflow and runtime expectations. |