For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

Segments

Define reusable semantic model filters for common business subsets.

Segments are predefined, reusable filters that package a boolean SQL-like predicate for use in queries and tooling. Instead of writing the same WHERE condition in every query, define it once as a segment and reference it by name. You can use the segments parameter within a semantic model to define segments.

For example, high-value accounts can be treated as a segment:

segments:
  - name: high_value_accounts
    expression: "{users.plan_type} IN ('pro', 'enterprise')"
    description: Paid plan users

Or use a segment to implement cross-column OR logic:

segments:
  - name: at_risk_users
    expression: "{users.status} = 'active' AND {users.plan_type} = 'free'"
    description: Free users who might churn

Parameters

Every field a segment supports, one section per key.

name

The identifier of a segment. Must be unique among measures and segments within a semantic model and follow the naming rules (^[a-zA-Z_][a-zA-Z0-9_]{0,63}$).

segments:
  - name: high_value_accounts
    expression: "{users.plan_type} IN ('pro', 'enterprise')"

expression

A boolean SQL-like predicate, written with {name.column} references, that defines the subset of rows the segment matches. Required.

description

Human-readable explanation of what the segment represents. Optional; defaults to an empty string.

public

Controls whether the segment is exposed to consumers. Defaults to true.

tags

Categorization labels for the segment. Validated against ^[a-zA-Z0-9.:_-]+$ and normalized to lowercase.

terms

Business glossary references for the segment, typically dotted FQNs. Validated against ^[a-zA-Z0-9._-]+$ and normalized to lowercase.

ai_context

Structured hints for AI/LLM consumers on this segment: instructions, synonyms, caveats, and worked examples. See AI context for the full field reference.


Segments vs. dimension filters

Since segments are just predefined filters, it can be difficult to decide when to use a segment instead of filtering on a dimension directly. A filter on a dimension works better when the filter value changes a lot between queries, for example filtering users.plan_type = 'enterprise' ad hoc. A segment earns its keep when it packages a complex, reusable predicate that many queries share, such as the AND/OR combination in at_risk_users above.


Validation

SegmentSpec validates segment definitions during vulcan plan. It checks that:

  • name and expression are both present

  • name is unique among measures and segments within the semantic model

  • expression references only columns on the current semantic model

  • Column references use the canonical {model}.column or bare column form, and the expression doesn't contain a subquery, CTE, lateral join, or column alias (logged as a warning by default; hard-fails when strict_semantic_validation: true)

Last updated

Was this helpful?