malloy-analysis-pitfalls
Skill116 starsChanged 2 months agoMITView on GitHub
Checks to run on a query and its numbers before a result is presented - wrong grain, fan-out, invented field names, mismatched filters, count vs distinct. The common data-analysis pitfalls.
In this repository45 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- fix-scan-findingSkill
- publisher-releaseSkill
- eval-answerSkill
- eval-diagnoseSkill
- eval-importSkill
- eval-improveSkill
- eval-judgeSkill
- eval-loopSkill
- eval-reportSkill
- malloy-analysis-reportSkill
- malloy-analysisSkill
- malloy-analyzeSkill
- malloy-chartsSkill
- malloy-dashboardsSkill
- malloy-data-app-designSkill
- malloy-debugSkill
- malloy-defineSkill
- malloy-discoverSkill
- malloy-documentSkill
- malloy-getting-startedSkill
- malloy-gotchas-modelingSkill
- malloy-gotchas-queriesSkill
- malloy-gotchas-renderingSkill
- malloy-html-data-app-embeddingSkill
- malloy-html-data-app-runtimeSkill
- malloy-html-data-appsSkill
- malloy-lookml-reviewSkill
- malloy-materializationSkill
- malloy-materialization-tuningSkill
- malloy-model-as-you-goSkill
- malloy-modelingSkill
- malloy-modelSkill
- malloy-notebook-chatSkill
- malloy-notebooksSkill
- malloy-patternsSkill
- malloy-phrase-detectionSkill
- malloy-powerbi-reviewSkill
- malloy-publishSkill
- malloy-queriesSkill
- malloy-reviewSkill
- malloy-scopeSkill
- malloySkill
- malloy-source-unreachableSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 7 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 31
Never guess field names. Use only the exact field paths defined in the model (find them with get_context).
- Distinctive: line 37
If the user asks to filter by "brand", confirm which dimension corresponds to "brand" in the model.
- Distinctive: line 40
If the user asks about "last quarter" but you don't apply a time filter, you are returning all-time data.
- Distinctive: line 59
If a "total" is suspiciously small or large, question it.
- Distinctive: line 68
When computing percentages or shares, be explicit about the denominator.
- Distinctive: line 79
If you break down a total by category, the categories should sum to the total (or close to it, accounting for nulls).
- Distinctive: line 85
Before interpreting results, check whether the row count makes sense.
- Distinctive: line 88
If a query returns no rows, don't report "there is no data." First verify that your filters are correct and the field names are right.
≈ “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.
Files
<!-- Copyright (c) Credible Data Inc. SPDX-License-Identifier: MIT -->Data Analysis Pitfalls
Watch for these common mistakes throughout the analysis workflow. When you encounter one, fix it before presenting results.
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.
Query Construction
Wrong grain / fan-out
Using dimensions or measures from a joined source that has a finer grain than the base source can silently multiply rows, inflating aggregates. For example, aggregating revenue while grouping by a line-item field may double- or triple-count totals. If your query touches fields from a joined source, compare count(key_field) to count(): if the row count is significantly higher than the distinct key count, you likely have fan-out.
That check reads in ONE direction only. count(joined.field) is a distinct count evaluated at the joined source's grain, so for an ordinary many-to-one join it is much SMALLER than count(), and that is the expected, correct result -- not missing data. Ten thousand flights joined to four hundred aircraft give count(aircraft.tail_num) of 400, and nothing is wrong. Do not read a low value as a coverage problem and do not abandon the answer over it. Coverage is measured at the base grain, by counting base rows whose joined value is null:
run: flights -> {
aggregate:
all_rows is count()
missing is count() { where: aircraft.aircraft_models.seats is null }
}An agent once refused a correct answer it had already computed because count(aircraft.tail_num) returned 36 against 17,875 flights; measured at the base grain, zero flights were missing a seat value.
Invented entity names
Never guess field names. Use only the exact field paths defined in the model (find them with get_context). A plausible-sounding name that does not exist in the model will produce an error, or worse, silently reference the wrong field.
Mismatched filter values
Dimensional values are case-sensitive and format-specific. Common mismatches include case differences ("Nike" vs "NIKE" vs "nike, inc."), partial matches ("New York" when the data has "New York City"), and aliased values ("USA" vs "United States"). A filter on a value that doesn't exist in the data silently returns zero rows without erroring. Always use the exact dimensional values from retrieval results, and if in doubt, run a distinct-values query on the dimension to confirm.
Filtering on the wrong field
If the user asks to filter by "brand", confirm which dimension corresponds to "brand" in the model. There may be multiple fields with similar names at different levels of the hierarchy.
Missing filters
If the user asks about "last quarter" but you don't apply a time filter, you are returning all-time data. Always check whether the question implies filters you have not yet applied.
Misinterpreted entities
A field can exist in the model and still be the wrong choice. For example, using revenue (which may be gross) when the question asks about profit, or treating a count measure as if it were a sum. Cross-reference the field definitions and #(doc) descriptions in the model to confirm a field means what you think it means.
Semantic ambiguity
Field names or descriptions sometimes suggest one interpretation while the actual values tell a different story, for example, a field labeled "annual ridership" containing values that look like average weekday traffic, or a field named revenue that appears to represent net revenue in practice. When values don't match expectations, note whether the ambiguity affects the answer and call it out.
Fragile ad-hoc definitions
When defining a new measure or dimension inline, common mistakes include assuming a field is numeric when it's actually a string, ignoring nulls in arithmetic (e.g., a - b yields null if either is null), and building logic around values that only cover a subset of the data.
Pay special attention to value coverage when defining a dimension that categorizes or subsets data. It's easy to capture too few values (missing categories that should be included) or too many (grouping in values that don't belong). For example, a pick expression that maps tier names to "Premium" and "Standard" might miss a tier that should be Premium, or a filter meant to isolate one product line might inadvertently include related but distinct products. Before relying on such a definition, run a distinct-values query on the underlying field to see the full set of values and confirm your logic handles them all correctly. This applies equally whether you define the logic as a new dimension or apply it directly as a where clause: the risk of incomplete value coverage is the same either way.
Hidden filters in views
Views can have built-in where clauses that pre-filter the data. A view named recent_orders might only include the last 90 days, or active_customers might exclude certain statuses. If the view's definition is available, read it to understand what filters are baked in; they may conflict with what the user is asking for. When in doubt, query the base source directly and apply filters explicitly.
Result Interpretation
Implausible magnitudes
If a "total" is suspiciously small or large, question it. Common causes: missing filters (too large), over-filtering (too small), wrong unit (dollars vs. cents), or fan-out from joins (inflated).
Nulls distorting aggregations
Null values are silently excluded from avg() and can make sum() results lower than expected. If a significant portion of a field's data is null, aggregations over that field may be misleading. When results seem off, compare total row count to a count of non-null values for the key field to gauge how much data is missing.
Confusing count vs. count distinct
count() counts rows while measures defined with count(field) count distinct values of that field. Using a row count when you need distinct values (or vice versa) is a frequent source of inflated or deflated numbers, especially when the query touches joined sources.
Percentage of what?
When computing percentages or shares, be explicit about the denominator. "30% of revenue" means nothing if you don't confirm what the total revenue is and whether it's filtered the same way.
Time period mismatches
Comparing metrics across different time periods without normalizing (e.g., comparing a full year to a partial quarter) produces misleading conclusions.
Extremes of a rate on a tiny denominator
"Which one is worst" ranked on a ratio hands the top spot to whichever group has the fewest rows: one failure out of three is a 33% failure rate, and it will outrank a group with thousands. Before reporting an extreme of any rate, look at what is underneath it. Apply the model's documented minimum volume if it has one; if it has none, pick a floor, say which floor you picked, and print the denominator next to the rate rather than the rate alone.
Verification Signals
Parts don't sum to the whole
If you break down a total by category, the categories should sum to the total (or close to it, accounting for nulls). If they don't, something is wrong with the grain or filters.
A total the model tells you not to take
The check above assumes the parts are additive. Sometimes they are not, and the model says so: a doc noting that one event can be logged on two layers, or that a measure is non-additive, is telling you the sum across that dimension double-counts. Do not print a total row across such a dimension, and least of all one the user did not ask for. If a total is genuinely wanted, say why the model does not support it and give the per-category figures.
Row count surprises
Before interpreting results, check whether the row count makes sense. An unexpectedly high row count often indicates fan-out from a join. An unexpectedly low count may mean an overly restrictive filter.
Zero or empty results
If a query returns no rows, don't report "there is no data." First verify that your filters are correct and the field names are right. The absence of results is usually a query problem, not a data problem.
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
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.

