For the complete documentation index, see llms.txt. This page is also available as Markdown.

Step 3: Domain Context

With domains defined, create the rules and guidance that apply to every query in each domain.

This step produces three files: domain-wide SQL rules that apply to every text-to-sql query, a clarification policy that controls when the agent asks follow-up questions, and an output format that controls how results are presented.


Why Domain Context Before Entities?

Domain context is a multiplier. Every entity you model later inherits these rules — the SQL standards apply to all queries, the clarification policy governs every response, and the knowledge baseline compounds with entity-level context at query time.

Getting domain context right before modeling entities means entity files only need to cover what is unique to that entity. The domain does the heavy lifting for everything shared.


3a: Domain Task Instructions

Location: .lynk/default/domain_context/default__task_inst__text_to_sql.md

This file answers: What SQL rules apply to every query in this domain?

Anything true for all entities belongs here. Entity task instructions only need to cover what is specific to that entity.

---
type: task-instructions
domain: "*"
tasks: "text-to-sql"
---

# SQL Generation Rules

## Always Apply

- Always exclude test accounts: filter `is_test_account = false` unless the user explicitly asks about test accounts
- Always exclude deleted accounts: filter `is_deleted = false` unless explicitly told otherwise
- Use `arr` as the revenue metric. Never use `total_paid` — it includes one-time professional services fees that inflate revenue

## Time and Fiscal Year

- The fiscal year starts February 1. Q1 = Feb–Apr, Q2 = May–Jul, Q3 = Aug–Oct, Q4 = Nov–Jan
- When filtering by quarter, use the fiscal definition above — not calendar quarters
- For cohort analysis, use `first_paid_at` as the customer start date, not the account creation date

## Query Patterns

- When asked about revenue trends, default to monthly granularity unless the user specifies otherwise
- Plan type values in the data are lowercase: 'starter', 'growth', 'enterprise' — filter accordingly
- For churn calculations, use the `churn_rate` metric on the `customer` entity directly — do not derive churn from subscription cancellation counts

What to put in domain task instructions:

  • Default filters that apply to most queries (exclusions for test and deleted records)

  • The canonical revenue metric and which fields to avoid

  • Date and calendar conventions (fiscal year, cohort start date)

  • Preferred query patterns when multiple approaches exist and one is correct

What to leave out:

  • Entity-specific SQL patterns (join nuances, entity-specific filters) — those go in entity task instructions

  • Business definitions and context — those go in knowledge files

  • Output formatting — that goes in the output format behavior file


3b: Clarification Policy

Location: .lynk/default/agent/clarification_policy.md

This file answers: When should the agent ask a follow-up question instead of running a query?

What goes here:

  • Specific ambiguities that recur in this domain (time periods, metric definitions, "active" meaning)

  • Explicit rules for when to proceed without asking — this prevents over-asking on simple questions

  • Format guidance for how clarification questions should be phrased


3c: Output Format

Location: .lynk/default/agent/output_format.md

This file answers: How should results be presented?

What goes here:

  • Tone and professional register for this audience

  • Table formatting requirements (title, percentage of total, post-table observations)

  • What metadata to always include at the end (filters, time range, metric definition)

  • Explicit exclusions that apply to this audience


Key Point

Domain task instructions are for query generation — they make SQL consistent across entities. Behavior files are for communication — they make responses consistent. They serve different layers and do not overlap.

A common mistake is putting output formatting guidance in knowledge files. Knowledge is loaded during query planning; behavior files are loaded during response generation. Formatting guidance in a knowledge file has no effect on how results are presented.

Last updated