Inference operations
Inference operations let a pipeline enrich warehouse rows with values produced by a model. An inference asset reads one tabular input, sends row-scoped structured requests to one or more providers, and writes the input fields plus generated fields to a table. Its warehouse connection and its model credential connections are separate concerns. See platform services, AI workflows, and secrets management for the surrounding platform context.
Inference asset boundary
An inference asset is a batch enrichment step, not an agent or a SQL generation step. It keeps the source row as the unit of work and publishes typed results that downstream pipeline assets can query.
flowchart LR
A[Input asset or query] --> B[Input rows]
B --> C[Rendered row prompts]
C --> D[Provider request groups]
D --> E[Validated structured values]
E --> F[Arrow batch]
F --> G[Destination table]
The asset requires table materialization with either merge or create+replace. A primary key gives each input row a stable table identity. The asset does not support views, append history, incremental keys, partitions, hooks, or checks on its own output; place quality checks on a downstream SQL asset when the warehouse connection cannot run them.
References: pkg/…/config.go• L28-49 pkg/…/config.go• L164-179 pkg/…/operator.go• L53-81
Input and output contract
Input rows
The input is exactly one of two forms: parameters.input_asset names an asset in the same pipeline, or parameters.input_query supplies a query. An input asset creates a visible pipeline dependency and is read with all columns. It must use the same warehouse connection as the inference asset. An input query keeps its declared run-time templating, so the asset author must declare any dependency separately.
Rows pass through without name normalization. Input and generated names must be unique without regard to letter case. Every primary-key field must exist, be non-null, and be unique in the input. max_rows limits the batch before model calls and defaults to 1,000.
References: pkg/…/config.go• L109-126 pkg/…/operator.go• L115-129 pkg/…/operator.go• L145-191 pkg/…/pipeline.go• L3193-3215
Generated fields
Each generated field has an inference definition with a prompt and a declared output type. Supported types are string, boolean, integer, and number. Prompts and the asset context are rendered for each row with only row available; generated fields cannot depend on other generated fields.
Columns with the same effective provider, model, and credential connection share one request per row. A field may override the provider or model. A provider change requires an explicit model, which keeps each request group unambiguous.
| Field rule | Result |
|---|---|
choices on a string | The provider must return one configured string. |
minimum or maximum on an integer or number | The returned value must stay within the inclusive bounds. |
levels on a TypeSafe number | The field becomes an ordered Score value. |
threshold on a TypeSafe boolean | A probability at or above the threshold becomes true. |
References: pkg/…/operator.go• L145-160 pkg/…/operator_test.go• L201-231 pkg/…/columns_test.go• L99-147
Provider configuration and credentials
Provider settings
The asset-level provider, model, and context define the default request group. system_prompt or its instructions alias adds shared guidance. Supported providers are OpenCode, OpenRouter, OpenAI, Anthropic, Google, and TypeSafe. A column can select a different provider, model, or named connection when its output needs a different account or request contract.
The top-level asset connection remains the warehouse connection. Model credentials use named Bruin connections and must have the provider's connection type. Resolution uses the column's explicit connection first, then the pipeline's default_connections[provider], then <provider>-default. Bruin checks the connection and API key before it reads input rows or sends requests. It does not use API-key environment variables for inference assets.
| Connection purpose | Selected by | Used for |
|---|---|---|
| Warehouse | Asset connection | Reading input and writing the destination table. |
| Model provider | inference_connection, pipeline defaults, or column override | Authenticating requests to the effective provider. |
References: pkg/…/config.go• L52-69 pkg/…/config.go• L71-81 pkg/…/config.go• L85-100 pkg/…/operator.go• L63-71
Request execution
Row request groups
The executor renders the context, shared instructions, and field prompts for each row. It then sends one structured request for each row and effective provider group. extract_parallelism limits all active provider-group requests together and defaults to 16, so increasing it can raise concurrent load across every provider used by the asset.
The request key includes the rendered content, output schema, provider, model, credential connection name, and token limit. The output schema includes rules such as TypeSafe choices and levels. This makes a changed prompt or schema a new request while allowing identical rendered requests from different rows to share a result.
References: pkg/…/config.go• L135-153 pkg/…/operator.go• L132-142 pkg/…/operator_test.go• L353-380 pkg/…/columns_test.go• L149-239
Provider calls
Each provider receives the row context and shared instructions through its native structured-output interface. TypeSafe uses its question model for Choice, Noul, and Score values. Other providers return a JSON object that matches the requested schema. A request has a 120-second attempt timeout. Rate-limit and server errors retry up to ten total attempts with provider hints or bounded backoff. Authentication, unsupported API features, malformed output, and refusal errors fail the asset without a free-text fallback.
References: pkg/…/operator.go• L132-142 pkg/…/operator_test.go• L176-199 pkg/…/operator_test.go• L235-256
Structured output contract
Structured output makes model responses data for the pipeline rather than text that the pipeline must parse. The request declares all generated fields as required, disallows extra fields, and validates the returned type, choice, and numeric range before any table load begins.
Provider output types
Most providers support the four basic field types. TypeSafe adds domain-specific question forms that map to the same stored values.
| Provider family | Supported result model |
|---|---|
| OpenCode, OpenRouter, OpenAI, Anthropic, Google | Required string, boolean, integer, or number fields. |
| TypeSafe Choice | A selected string from the configured choices. |
| TypeSafe Noul | A probability stored as a number, or converted to a boolean by threshold. |
| TypeSafe Score | A weighted value across two to ten ordered levels. |
Provider model support is not preflighted universally. A provider can reject a model or route that does not support the requested schema. The asset then fails rather than parsing an unstructured answer.
References: pkg/…/operator_test.go• L235-249 pkg/…/operator_test.go• L258-303 pkg/…/columns_test.go• L99-147
Result caching
Inference has a result cache to avoid repeating identical model work. A run uses a 1,024-entry memory cache and can reuse persistent result files scoped to the local repository, pipeline, asset, warehouse connection, and destination. Concurrent identical requests share one in-flight call. Successful results are saved before the destination load, so a later load retry can reuse them.
Set cache: false to bypass memory reads, disk reads and writes, and in-flight deduplication. Existing entries remain available for a later cache-enabled run. The legacy force parameter is rejected; use cache: false when a fresh request is required. Cache files contain generated values, not prompts or API keys, but they are not encrypted and do not expire automatically.
Changing a request group's prompt or schema invalidates that group without forcing unrelated groups to run again. This allows a later run to reuse unchanged row results while regenerating the affected output group.
Result caching is separate from provider prompt caching. Provider prompt caching may reuse a shared instruction prefix, while Bruin's result cache avoids a model call altogether. A cache report distinguishes cached results from provider-reported prompt cache usage.
References: pkg/…/operator.go• L86-113 pkg/…/operator.go• L132-142 pkg/…/operator_test.go• L134-174 pkg/…/operator_test.go• L176-199 pkg/…/columns_test.go• L225-239
Arrow data interchange and materialization
Arrow is the boundary between inference row processing and table loading. The input is read as a typed Arrow record when the warehouse supports it, or converted to Arrow with loss checks. The generated fields are appended to that record and written as an Arrow IPC file for the shared ingestion path.
Generated integer values use Arrow int64, and number values use float64. Unknown source types, missing decimal precision, or conversions that would round data stop the run instead of silently changing values. Explicit column type and decimal declarations can supply schema information when a driver does not provide enough metadata.
Materialization controls how the Arrow batch reaches the destination:
mergeupdates or inserts rows by primary key. It does not remove destination rows that disappeared from the source.create+replacerebuilds the destination from the current input, including values reused from the cache.- Full refresh rebuilds the table but still permits valid cached results. Use
cache: falsewhen fresh model calls are required.
References: pkg/…/operator.go• L222-260 pkg/…/operator_test.go• L134-174 pkg/…/operator_test.go• L235-256
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the distinction between the warehouse connection and each provider credential connection.
- Keep provider, model, connection, and schema fields aligned with the result-cache identity.
- Preserve the rule that input rows and generated fields cannot share a case-insensitive name.
- Preserve primary-key validation because merge identity and duplicate-row detection depend on it.
- Keep generated Arrow types aligned with the destination loader's supported types.
- Keep provider-specific structured-output limits aligned with local validation. Do not add a free-text fallback.
- Keep
input_assetdependency registration aligned with same-connection input validation. - Keep quality-check routing aligned with the destination inferred from the warehouse connection.
- Keep
system_promptandinstructionsas exclusive names for the same shared guidance. - Keep schema changes that affect one request group from invalidating unrelated cached groups.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Provider connection is missing, has the wrong type, or has no API key | The asset stops before reading input or making billable calls. | Resolve a named connection whose type matches the effective provider. |
| Input has a null or duplicate primary key | The asset cannot identify the destination row and does not load results. | Supply a non-null unique primary key in the input. |
| Provider returns extra, missing, malformed, or out-of-range fields | The asset fails before destination loading. | Use a model and route that support the requested structured schema. |
| Input type is unknown or a decimal or float conversion would lose data | Arrow conversion fails instead of changing the source value. | Use native Arrow input or declare a precise supported column type. |
| Cached result is stale for the required run | The asset reuses a prior generated value. | Set cache: false for an independent fresh generation. |
Both system_prompt and instructions are set | Configuration validation fails before execution. | Set only one shared-guidance parameter. |
| Quality checks use a warehouse without an inference check executor | The asset fails before model requests or destination loading. | Use a supported warehouse or move checks to a downstream SQL asset. |
Key files
| File | Why to read it |
|---|---|
| pkg/…/operator.go | Shows the end-to-end asset lifecycle from validation through input read, inference, and table publish. |
| pkg/…/config.go and pkg/…/columns.go | Define the asset and generated-column contract. |
| pkg/…/input.go | Explains the two input forms and same-warehouse dependency rule. |
| pkg/…/credentials.go and pkg/…/pipeline.go | Show provider connection selection and credential checks. |
| pkg/…/requests.go and pkg/…/structured.go | Explain row request grouping, structured schemas, and result validation. |
| pkg/…/cache.go | Defines result reuse and in-flight request sharing. |
| pkg/…/arrow.go | Defines typed input conversion and Arrow output interchange. |