mcpField
F
filterql-builder

filterql-builder

github.com/lyticsData & databases449 installsUpdated 3w ago
Repository

About filterql-builder

filterql-builder converts structured conditions into valid FilterQL expressions. It is intended for constructing filters without API access, with syntax based on field types and AND/OR/NOT grouping.

Key features

  1. 01Map operators to field types
  2. 02Compose AND/OR/NOT conditions
  3. 03Generate descriptive alias slugs
  4. 04Escape quoted values
  5. 05Flag incompatible operators

Use cases

  1. 01Turn audience criteria into FilterQL
  2. 02Build grouped filters for a target table
  3. 03Correct an invalid expression or operator

MCP support

The input does not describe an MCP connection or MCP-specific behavior.

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/lytics/agent-skills --skill filterql-builder

After installing, type/filterql-builderin Claude Code to confirm it loaded.

Details

From the project README

FilterQL Builder

Purpose

Translate structured conditions into valid FilterQL syntax. Takes field/operator/value tuples with AND/OR grouping and produces a syntactically correct FilterQL string.

Environment

  • None required (pure construction, no API calls)

Inputs

  • Conditions: list of (field, operator, value) tuples
  • Grouping: AND/OR/NOT composition
  • Table: target table (default: user)
  • Alias: segment slug name

Behavior

Step 1: Map Each Condition to FilterQL Syntax

For each condition, use the type-operator compatibility matrix from ../references/field-types.md:

Field TypeNatural LanguageFilterQL
stringequals "X"field = "X"
stringnot "X"field != "X"
stringcontains "X"field CONTAINS "X"
stringlike patternfield LIKE "pattern*"
stringone of A,B,Cfield IN ("A", "B", "C")
boolis truefield = true
boolis falsefield = false
int/numbermore than Nfield > N
int/numberat least Nfield >= N
int/numberless than Nfield < N
dateafter N days agofield > "now-Nd"
datebefore N days agofield < "now-Nd"
datewithin last N hoursfield > "now-Nh"
[]string (set)has "X"field INTERSECTS ("X")
[]string (set)doesn't have "X"field NOT INTERSECTS ("X")
anyhas any valueEXISTS field
anyis emptyNOT EXISTS field
Step 2: Compose Conditions

Wrap conditions in AND/OR/NOT:

FILTER AND (
  condition1,
  condition2,
  OR (condition3, condition4)
) FROM table ALIAS slug_name

Rules:

  • Single condition: FILTER condition FROM table ALIAS slug
  • Multiple conditions default to AND
  • NOT can wrap any single condition or group
  • Parentheses required for AND/OR groups
  • Comma-separate conditions within groups
Step 3: Generate Slug Name

Convert the alias to a valid slug:

  • Lowercase
  • Replace spaces with underscores
  • Remove special characters
  • Keep it descriptive but concise
Step 4: Output

Return the complete FilterQL string:

FILTER AND (country = "US", visitct > 5) FROM user ALIAS us_active_visitors

Date Math Reference

PeriodSyntaxExample
Hours"now-Nh""now-24h" = 1 day ago
Days"now-Nd""now-30d" = 30 days ago
Weeks"now-Nw""now-4w" = 4 weeks ago
Months"now-NM""now-6M" = 6 months ago
Years"now-Ny""now-1y" = 1 year ago

Common conversions:

  • 1 year = "now-1y" or "now-8760h" or "now-365d"
  • 90 days = "now-90d" or "now-2160h"
  • 1 week = "now-1w" or "now-7d" or "now-168h"

Error Handling

  • If a field type is incompatible with the requested operator, suggest the correct operator
  • If values contain quotes, escape them
  • If the FilterQL is syntactically invalid, identify and fix the issue

Dependencies

  • References: ../references/filterql-grammar.md, ../references/field-types.md

Comments

Markdown supported