Skip to main content

Prerequisites

  • A LexQ account (sign up free)
  • An API key (created in Console → Management → API Keys)

Step 1: Create a Policy Group

1

Open the Console

Navigate to console.lexq.io and sign in.
2

Create a Group

Go to Policy Groups → Create Group.
  • Name: discount-policy
  • Priority: 1
  • Execution Mode: Allow All (NONE)
3

Create a Version

Inside your new group, click Create New Draft. This creates a DRAFT version where you can add rules.

Step 2: Define a Rule

1

Register the Fact

The action below writes to paymentAmount, so register it as a fact first. Go to Management → Fact Definitions, click Add Fact, and enter:
  • Key: paymentAmount
  • Display Name: Payment Amount
  • Data Type: NUMBER
A rule cannot be saved while one of its actions writes to an unregistered fact (ACT-032).
2

Add a Rule

In the Rule Edit tab, click Add Rule.
  • Name: High-Value Discount
  • Priority: 1
3

Set the Condition

Add a condition using the paymentAmount fact:
4

Add an Action

Add a MUTATE_FACT action:
  • Target Fact (targetVar): paymentAmount
  • Operator (operator): SUB (subtract from targetVar)
  • Method (method): Percentage
  • Value (operand): 10 (reduces targetVar by 10%)
userId and userTags are pre-registered and ready to use. Domain-specific facts like paymentAmount or customerTier are user-defined — see Fact Definitions.

Step 3: Test with Dry Run

Before deploying, validate your rule with a Dry Run:
You should see the mutated paymentAmount: 135000 in the response, and paymentAmount__delta: -15000 in generatedVariables (the signed change applied by the rule).

Step 4: Publish and Deploy

1

Publish

Click Publish Version. The version transitions from DRAFT to ACTIVE and is now locked — no further edits allowed.
2

Deploy

Click Deploy to Live. Enter a deployment memo and confirm. Your policy is now live and processing traffic.

Step 5: Execute via API

Call the execution endpoint from your application:
These snippets are the call itself. For a complete service around it — error handling, idempotency, and types — see the runnable examples on GitHub (Java and TypeScript).

What’s Next?

Fact Definitions

Add custom variables like customerTier or orderRegion.

Impact Simulation

Test policies against bulk data before deploying.

Policy Execution

Learn about all 4 execution modes (single, version, batch, composite).

CLI & MCP

Manage policies from the terminal or via AI agents.