Skip to main content
AI Sort Builder is currently in Beta. Contact your Layers account manager or support team to request access.

Overview

AI Sort Builder allows you to configure sort orders using natural language descriptions instead of manually creating attributes, metrics, and sorting rules. The AI analyzes your request and automatically generates the necessary configuration, including calculated attributes, LayersQL metrics, and sorting expressions.

Prerequisites

  • AI Sort Builder must be enabled for your store (contact your account manager)
  • Access to the Sort Orders section in your Layers dashboard
  • An existing sort order to modify (the AI Builder is not available when creating new sort orders)

Using AI Sort Builder

Accessing the AI Builder

  1. Navigate to Sort Orders in your Layers dashboard
  2. Open an existing sort order for editing
  3. Click the AI Builder button (marked with a Beta badge) in the Sorting Expressions section
The AI Builder opens in a dialog with a chat interface where you can describe your desired sorting behavior.

Writing effective prompts

Describe your sorting goals in natural language. The AI understands common ecommerce concepts and can generate complex configurations from simple descriptions. Example prompts:
  • “Sort by popularity, boost new arrivals”
  • “Show best sellers first, then sort by price low to high”
  • “Prioritize products with high margins, demote out-of-stock items”
  • “Balance between popularity and profit margin, favoring popularity 70/30”
  • “Sort by most viewed in the last 30 days, boost items added this week”
Tips for better results:
  • Be specific about time windows (e.g., “last 30 days” vs. “recent”)
  • Mention if you want weighted combinations and specify the weights
  • Describe priority rules clearly (boost/demote conditions)
  • Reference specific product attributes if you know they exist in your catalog

Understanding the generated configuration

After you submit a prompt, the AI generates a configuration that may include: Calculated attributes: Custom product attributes created using JSONLogic expressions. These derive new properties from existing product data (e.g., “is new arrival” based on publish date). LayersQL metrics: Analytics-based metrics that aggregate event data per product (e.g., “30-day view count” or “7-day revenue”). Sorting rules: The actual sorting configuration that determines product order, including direction (ascending/descending), weights, and priority conditions. The AI provides an explanation of what the configuration does and shows a preview of all generated resources.

Reviewing and applying the configuration

Before applying the configuration:
  1. Review the explanation to ensure it matches your intent
  2. Check the list of new attributes and metrics that will be created
  3. Verify the sorting rules align with your merchandising goals
Actions available:
  • Regenerate: Ask the AI to create a new configuration if the current one doesn’t meet your needs
  • Apply: Accept the configuration and add it to your sort order form
Applying the configuration creates new attributes and metrics in your store and updates the sort order form. You must still save the sort order to persist these changes.

Iterative refinement

You can continue the conversation with the AI to refine the configuration:
  1. After reviewing the generated configuration, describe what you’d like to change
  2. The AI maintains conversation context and can adjust the configuration based on your feedback
  3. Each iteration generates a new configuration that you can review and apply
Example refinement:
  • Initial prompt: “Sort by popularity”
  • Follow-up: “Actually, also boost products with high margins”
  • The AI adjusts the configuration to include margin-based boosting

How the AI works

Generation process

When you submit a prompt, the AI:
  1. Analyzes your store’s existing attributes and metrics
  2. Understands your natural language description
  3. Generates the necessary calculated attributes and metrics
  4. Creates sorting rules that implement your desired behavior
  5. Validates the configuration to ensure it’s syntactically correct
The generation happens asynchronously with real-time status updates via WebSocket. You’ll see progress indicators as the AI works.

Validation and retries

The AI automatically validates generated configurations and retries up to 3 times if validation fails. This ensures you receive a working configuration that can be applied to your sort order. If generation fails after all retry attempts, you’ll see an error message explaining what went wrong. You can try rephrasing your prompt or providing more specific details.

Using existing resources

The AI checks your store’s existing attributes and metrics before creating new ones. If a suitable attribute or metric already exists, the AI references it instead of creating a duplicate. For example, if you already have a “Product Views” metric, the AI will use it when you ask to “sort by popularity” rather than creating a new metric.

Common use cases

Popularity-based sorting

Prompt: “Sort by most popular products first” What the AI generates:
  • A LayersQL metric counting product views
  • A sorting rule ordering products by view count (descending)

New arrivals with popularity tiebreaker

Prompt: “Show new arrivals first, then sort by popularity” What the AI generates:
  • A calculated attribute identifying products published in the last 30 days
  • A LayersQL metric for product views
  • Sorting rules that prioritize new arrivals, then sort by popularity

Weighted combination

Prompt: “Balance between popularity and profit margin, favoring popularity 70/30” What the AI generates:
  • A LayersQL metric for product views
  • A weighted sorting configuration combining views (70%) and margin (30%)

Priority rules with conditions

Prompt: “Boost featured products, demote out-of-stock items, then sort by price” What the AI generates:
  • Priority rules boosting featured products
  • Priority rules demoting out-of-stock items
  • A price-based sort for remaining products

Troubleshooting

The AI Builder button doesn’t appear

Cause: AI Sort Builder is not enabled for your store. Solution: Contact your Layers account manager or support team to request access to the AI Sort Builder beta.

Generation fails repeatedly

Cause: The prompt may be too vague or request something that’s not possible with the available data. Solution: Try rephrasing your prompt with more specific details. Mention specific attributes or time windows. If the issue persists, contact support.

Generated configuration doesn’t match expectations

Cause: The AI may have misunderstood your intent or made assumptions about your catalog. Solution: Use the chat interface to refine the configuration. Describe what’s wrong and what you’d like to change. The AI maintains conversation context and can adjust accordingly.

Status updates not appearing

Cause: Real-time updates may not be working in your browser. Solution: Try refreshing the page and reopening the AI Builder. If the issue persists, contact support for assistance.

Best practices

Begin with a straightforward description of your primary sorting goal. Use the iterative refinement feature to add complexity based on the initial results.
When asking for time-based metrics (popularity, recency), specify the time window (e.g., “last 7 days” or “last 30 days”) for more predictable results.
Always review the generated configuration before applying it. Check that the attributes, metrics, and sorting rules align with your merchandising strategy.
After applying and saving a configuration, use the sort order preview feature to verify that products are ordered as expected.
Mention specific attributes or metrics you know exist in your store. The AI will reference them instead of creating duplicates.

Technical details

Calculated attributes

Calculated attributes use JSONLogic expressions to derive new product properties. The AI generates these when your prompt requires custom logic that isn’t available in existing attributes. Example JSONLogic for “is new arrival”:
{
  "if": [
    {"<=": [{"var": "_attribute:days_since_published"}, 30]},
    1,
    0
  ]
}
This expression returns 1 if the product was published within the last 30 days, otherwise 0.

LayersQL metrics

LayersQL metrics aggregate analytics data per product. The AI generates these when your prompt references popularity, sales, or other event-based concepts. Example LayersQL for “30-day views”:
SHOW count() AS views 
FROM products 
WHERE created_at >= now() - interval '30 days' 
GROUP BY product_id
This query counts product view events from the last 30 days, grouped by product.

Sorting rules

Sorting rules define how products are ordered. The AI generates these based on your prompt, including:
  • Direction: Ascending or descending
  • Weight: For weighted combinations (must sum to 100 in a group)
  • Operator and value: For priority rules (boost/demote conditions)

See also