hint('Always exclude test accounts with email ending in @test.com')hint('Use created_at for order dates, not updated_at')hint('The users table contains both customers and employees')
example({ question: 'show me churned customers', answer: `SELECT * FROM customers WHERE status = 'churned' ORDER BY churned_at DESC`, note: 'Status values are lowercase'})example({ question: 'monthly revenue trend', answer: ` SELECT DATE_TRUNC('month', created_at) AS month, SUM(amount) AS revenue FROM orders WHERE status = 'completed' GROUP BY month ORDER BY month DESC `})
explain({ concept: 'soft delete pattern', explanation: 'Records are not physically deleted. Instead, deleted_at timestamp is set.', therefore: 'Always add WHERE deleted_at IS NULL to exclude soft-deleted records'})explain({ concept: 'status lifecycle', explanation: 'Orders move: pending → processing → completed OR cancelled', therefore: 'Use status IN ("completed", "cancelled") for finalized orders'})
clarification({ when: 'User asks for "revenue" without specifying gross vs net', ask: 'Do you mean gross revenue or net revenue (after refunds)?', reason: 'Business has separate metrics for gross and net revenue'})clarification({ when: 'User asks for "active users" without timeframe', ask: 'Active in the last 30 days, 90 days, or year?', reason: 'Multiple definitions of "active" exist'})
function quirk(config: QuirkConfig): ContextFragmentinterface QuirkConfig { issue: string; workaround: string;}
Parameters:
issue - The data anomaly
workaround - How to handle it
Example:
quirk({ issue: 'Legacy orders have NULL in created_at column', workaround: 'Use COALESCE(created_at, migrated_at) for date filtering'})quirk({ issue: 'Email addresses before 2020 were not normalized to lowercase', workaround: 'Use LOWER(email) for case-insensitive matching'})
styleGuide({ prefer: 'Full table names as aliases (users AS users)', never: 'Abbreviated aliases (u, oi, t1, t2)'})styleGuide({ prefer: 'Explicit column names in SELECT', never: 'SELECT * in production queries', always: 'Include ORDER BY for deterministic results'})
// Terms for abbreviationsterm('LTV', 'lifetime value'),// Hints for conventionshint('Use subscription_start_at for cohort analysis'),// Quirks for data issuesquirk({ issue: 'Trial MRR included before March 2024', workaround: 'Exclude trials: WHERE plan_name != "trial"'})