agentleFS
malloydatamalloydata/publisher/skills/malloy-debug/SKILL.md

malloy-debug

Skill116 starsChanged 2 months agoMITView on GitHub

Fix Malloy compile errors and understand error messages. Use when encountering errors in .malloy files, user says "fix this error", "malloy error", "compile error", "syntax error", or sees 20+ cascading errors.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Otherwise, compile by running: Run any query against the source with your query tool and read the error it returns.

    line 19
  2. Distinctive:

    Only ask the user to open the file in an editor when you know they have the model open in one.

    line 21
  3. Distinctive:

    Look at FIRST error, ignore all others

    line 27
  4. Very specific:

    Call search_malloy_docs with the error message if unsure

    line 28
  5. Very specific:

    Note on number: Only the bare word needs backticking.

    line 58

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- Copyright (c) Credible Data Inc. SPDX-License-Identifier: MIT -->

Debugging Malloy Errors

Tool names are written bare here - get_context, execute_query, search_malloy_docs. The exact prefixed name depends on the host surface; match each against the tools you actually have.

Get Diagnostics

Hosts expose errors differently, so take the best path you actually have:

  1. An editor-diagnostics tool, if your host offers one - call it on the file and read the errors straight out.
  2. Otherwise, compile by running. Run any query against the source with your query tool and read the error it returns. Every host that can run Malloy can do this, including chat surfaces with no editor.

Only ask the user to open the file in an editor when you know they have the model open in one. On a hosted chat surface there is no local checkout to open, and the query path above is the one that works.

Strategy

Errors cascade. Later errors may be caused by or hidden behind earlier ones. Fix the FIRST error only, re-check diagnostics, repeat. Do not attempt to fix multiple errors at once.

  1. Look at FIRST error, ignore all others
  2. Call search_malloy_docs with the error message if unsure
  3. Fix that one issue, re-check diagnostics
  4. Repeat until clean. New errors may appear as earlier ones are resolved

Quick Fixes

ErrorFix
"Unknown field"Check typo, source order, wrong source, or missing import
"Can't use type string"Cast: field::number
"Aggregate not allowed in where"Use having: instead
20+ random errorsBacktick reserved word (`Date`, `Hour`, `number`)
Can't find field 'X' to set access modifierAn include {} sits before the extend { rename: }. Rename first, then include {} naming the field by its new name (see skill:malloy-gotchas-modeling § Field Management)
IO Error: No files found that match the pattern "data/x.csv"Data-file path, not the model. Relative duckdb.table() paths resolve against the DuckDB workingDirectory; Publisher sets it to the package root, but a relative workingDirectory in malloy-config.json resolves against the process cwd. Make it absolute (see skill:malloy-gotchas-modeling § Relative Data-File Paths). The "not defined" errors under it are cascade, not real
Import path errorsCheck paths: import "orders.malloy". All files should be in the same directory (flat layout)
unexpected 'from'from() was removed from the language. Use the query directly: source: x is q extend {...}, or source: x is (q -> {...}) extend {...}
Query-based source errorsVerify the source query returns the expected columns, check that imported sources are defined
"Cannot redefine 'X'"Field already exists from query-based source (-> { group_by, aggregate }). Remove the dimension, add only NEW derived fields in extend {}. Use include {} to add #(doc) tags to existing fields.

Gotchas Checklist

Backtick Reserved Words

// WRONG                        // RIGHT
dimension: d is Date::date      dimension: d is `Date`::date

Common reserved words: Date, Timestamp, Type, Hour, source, year, month, day, week, quarter, count, sum, avg, min, max, number, string, boolean, true, false, order, select, from, where, index, table, time, now, today, range, window, row, current

When in doubt, backtick it. See the Malloy docs (https://docs.malloydata.dev) for the full categorized list of reserved words.

Note on number: Only the bare word needs backticking. Compound names like account_number are fine.

Use is not null for NULL Checks

// WRONG                        // RIGHT
is_sold is sold_at != null      is_sold is sold_at is not null

Call Date Functions, Don't Access as Properties

// WRONG                        // RIGHT
dow is created_at.day_of_week   dow is day_of_week(created_at)

Properties: .month, .year, .day | Functions: day_of_week(), week(), hour()

Use having: for Aggregate Filters

// WRONG                        // RIGHT
where: order_count > 10         having: order_count > 10

Cast Strings Before Aggregating

// WRONG                        // RIGHT
avg(score)                      avg(score::number)

Use Boolean Literals Without Quotes

// WRONG                        // RIGHT
where: active = 'true'          where: active = true

Alias Joined Fields Before Using in order_by

// WRONG                        // RIGHT
group_by: races.year            group_by: yr is races.year
order_by: races.year            order_by: yr

Use Method Syntax for Joined Aggregates

// WRONG                        // RIGHT
sum(items.cost)                 items.cost.sum()

Define Lookup Tables First (or Use Imports)

// Single file: define lookup tables before referencing them
// Multi-file: use import statements
import "customers.malloy"

source: orders is conn.table('orders') extend {
  join_one: customers with customer_id  // Works because customers imported
}

Use nullif for Division

// WRONG                        // RIGHT
a / b                           a / nullif(b, 0)

Cross-File Errors

ErrorFix
"Can't find source X"Add import "X.malloy" at top of file (all files in same directory)
Wrong import pathAll .malloy files should be in the package root (flat layout). Use import "orders.malloy", not import "../sources/orders.malloy"
Circular importsSource A imports Source B which imports Source A. Restructure to break the cycle
Query-based source "Can't find field"Verify the source query's GROUP BY and aggregate fields match what you reference in extend {}

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.