malloy-queries

Provides Malloy query syntax patterns, error fixes, and chart annotation rules for semantic model queries.

Updated Jun 3, 2026
One-click install
npx skills add https://github.com/credibledata/credible-plugin --skill malloy-queries-credibledata
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: malloy-queries
Source: https://github.com/credibledata/credible-plugin/tree/main/codex/skills/malloy-queries
Command: npx skills add https://github.com/credibledata/credible-plugin --skill malloy-queries-credibledata

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Malloy queries against semantic models is error-prone: reserved keywords break aliases, aggregates get mixed with dimensions, date comparisons fail, and chart annotations end up in the wrong place. This Skill gives Claude a complete reference of correct Malloy patterns and known error fixes so queries compile and return correct results on the first attempt. ## Core Features & Use Cases - Query Pattern Library: Ready-to-use templates for aggregations, group-bys, time trends, filtered queries, percent-of-total with all(), conditional dimensions with pick, and window functions with calculate:. - Syntax Rules: Authoritative guidance on join paths via dot notation, @ date literals, where: vs having:, regex string matching with ~, order_by: constraints, and reserved-word pitfalls. - Error Diagnosis Table: Maps common Malloy error messages (e.g., "Cannot compare a timestamp to a number", "field is a bar chart, but is not a repeated record") to their causes and fixes. - Use Case: When asked to "break down revenue by region for Q1", Claude grounds itself with get_context, composes a valid Malloy query using these patterns, runs it via execute_query, and fixes any compilation errors using the diagnosis table. ## Quick Start Ask Claude to write and run a Malloy query such as "show monthly revenue for the last year as a line chart" and it will apply these patterns automatically.

Frequently Asked Questions about malloy-queries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a Malloy query with group by and aggregation?

Use the run: source -> { group_by: dimension; aggregate: measure } pattern, with optional order_by and limit. Dimensions go in group_by and measures in aggregate; never mix them, and filter rows with where: before aggregation or aggregates with having: after.

How do I filter Malloy queries by date range?

Use the ? apply operator with partial-date literals, such as where: order_date ? @2025-Q3 or @2025-06 to @2025-09. Never compare a timestamp to a bare integer like order_date.year >= 2020; use @2020-01-01 literals instead.

Why does my Malloy query fail with 'no viable alternative at input'?

This usually means a reserved keyword like month or year was used as an alias or function call, or fields were separated with semicolons. Rename the alias (e.g., order_month), use backticks, and separate fields with commas or newlines.

What is the difference between where and having in Malloy?

where: filters raw rows before aggregation and only sees dimensions; having: filters aggregate results and only sees measures. Putting an aggregate in where: or a dimension in having: is the most common Malloy query error.

How do I count distinct values in Malloy?

Use count(field) for a distinct count of that field and count() for a row count. Malloy has no count(distinct field) syntax, and count(*) is invalid.

Where do chart annotations go in a Malloy query?

Chart tags like # bar_chart or # line_chart go before run:, view:, or nest:, never inside curly braces. Placing them inside { } causes the error 'field is a bar chart, but is not a repeated record'.