Skip to content

Report builder

Poor reporting is the most common reason an organisation replaces its LMS. The report builder lets an administrator pick a dataset, choose columns, filters, grouping and a date range, save the result as a report, share it and schedule it. It is built in steps (ADR 0194). This page covers what exists today: the dataset registry and the report definition that is compiled into a safe query.

Analytics > Report builder (/analytics/report-builder, shown to everyone with the permission reporting_read) builds the same definitions without writing JSON:

  1. Dataset: pick one from the datasets you may run. A short description says what a row is.
  2. Kind of report: List rows (choose columns; personal columns are marked) or Group and aggregate (group by columns, dates with a day, week, month, quarter or year bucket, and aggregates with a name each).
  3. Filters, Date range (a period that is worked out on every run, or custom dates) and Order and size.
  4. Preview shows at most 500 rows and says how many there are. Small groups that were withheld are explained above the table and appear as one marked row; the text is the same for every viewer.
  5. Save report asks for a name, an optional description and who sees it: only you and the people who manage reports, or the roles you name. The note in the dialog repeats that sharing shares the report, not the data.

Below the builder, Saved reports lists the reports you can see, who they are shared with, whether they are ready, need repair or cannot be run with your permissions, and when they last ran. Open loads a report into the builder (then Save changes updates it and Save as a new report copies it), Export as CSV and Export as JSON lines download a file, and Delete asks first. Every control has a label, the whole screen works with the keyboard, results are real tables, and state changes are announced to screen readers (WCAG 2.2 AA, checked with axe in the admin browser tests). The screen is available in English, Polish and Chinese.

A dataset is a set of rows a report can be built on. The package that owns the data registers it, so a dataset appears only when its package is installed and its tables exist.

Dataset One row is Permission to run it
assignments a required-training assignment: learner, course, due date, outcome, certificate compliance_report
certificates a course certificate with the course version it attests compliance_report
audit a hash-chained Living Course audit entry (needs Living Course) compliance_report
authoring a course built with the Course Builder: time, cost, counts and the split of AI elements (authoring metrics) authoring_metrics_read
ai_usage a model call: task, model, tokens, cost in USD, latency reporting_ai_usage

Every dataset declares its columns: type (string, int, decimal, bool, date, datetime or enum), the filter operators it accepts, whether it can be grouped or aggregated, and whether it holds personal data (learner names and e-mail addresses). Personal columns are never groupable or aggregatable. A report can only use columns declared here: there is no way to name a table or write SQL.

What the datasets leave out on purpose:

  • ai_usage has no prompt or response text, no error text, no request or subject ids and no user.
  • audit has no IP address, user agent or free-form payload, as in the audit export.
  • authoring has no per-person figures. Review time is empty, never zero, until it is recorded.
  • A learner who was deleted is not named in assignments or certificates; the id stays, so the row can still be counted.

GET /api/admin/reporting/datasets (permission reporting_read, seeded for administrators and tutors) returns the datasets the caller may run, each with its columns. A tutor sees only the datasets whose permission they hold.

Terminal window
ulams reporting datasets --json

Each entry has key, label, description, permission, subject_column (the learner column used for small-group protection, null when the dataset holds no learner data), aggregate_only, date_columns and columns.

A report definition is JSON (schema report-definition/v1, in the reporting package). It asks one dataset for rows or for groups:

{
"dataset": "assignments",
"filters": [{ "column": "status", "op": "in", "value": ["overdue", "assigned"] }],
"dateRange": { "column": "assigned_at", "preset": "last_90_days" },
"groupBy": ["course_title", { "column": "assigned_at", "bucket": "month" }],
"aggregates": [{ "fn": "count_distinct", "column": "user_id", "as": "learners" }],
"sort": [{ "column": "learners", "dir": "desc" }],
"limit": 1000
}
Part Meaning
columns A row-level report: the columns to list. Leave it out for a grouped report.
filters All of them apply. Operators: eq, neq, in, not_in, lt, lte, gt, gte, between, contains (ignores case), is_null (true or false). Each column accepts only the operators its type allows, and values must have the column’s type.
dateRange A date column and either a preset (last_7_days, last_30_days, last_90_days, last_12_months, this_month, last_month, this_quarter, this_year, last_year) or inclusive from and to dates. A preset is worked out every time the report runs.
groupBy A column name, or a date column with a bucket (day, week, month, quarter, year; weeks start on Monday). The output column of a bucket is named <column>_<bucket>.
aggregates count, count_distinct, sum, avg, min, max, each with an output name (as). sum and avg need a number, min and max a number or a date.
sort, limit Output columns and the most rows the report returns.

A grouped report returns its groups followed by its aggregates. Names are looked up in the dataset’s declared columns, values are sent to the database as parameters, and the only SQL words that come from outside the dataset are the fixed list above, so a definition cannot read a table or column the dataset does not declare. Personal columns can be listed in a row-level report (and are then recorded like an export: who, which dataset, how many rows) but never grouped, aggregated, or used to filter a grouped report.

POST /api/admin/reporting/query (permission reporting_read and the permission of the dataset; a token needs only reports:read, because a preview changes nothing) runs a definition with the caller’s own permissions and returns at most 500 rows and the total:

Terminal window
ulams reporting query --dataset assignments --group-by '["course_title"]' \
--aggregates '[{"fn":"count_distinct","column":"user_id","as":"learners"}]' --json

The answer has data.columns (name, type, label), data.rows and meta: mode (rows or grouped), total_rows, preview_rows, truncated, withheld_groups and min_group_size. A definition that cannot run answers 422 with the problem by path, for example filters.0.op. A grouped report with more than 100 000 groups is refused.

On a dataset that holds learners (assignments and certificates), a grouped report never shows a group with fewer distinct learners than the threshold, 10 by default (REPORTING_MIN_GROUP_SIZE; when it is not set, the Learner Insights threshold LEARNER_INSIGHTS_MIN_GROUP_SIZE is used, so one number rules). The group’s figures are not sent at all: it is replaced by one row marked _withheld, with the text “withheld (fewer than 10 learners)” in the first group column and empty figures.

Withholding one group alone would not protect it: the total minus the visible groups would give it back. So the withheld groups together must span at least the threshold in distinct learners. When they do not, the smallest visible group is withheld with them. Learners who are in several groups (a learner in two courses) are counted once, not added up. meta.withheld_groups says how many groups are behind the row, never how many learners. A grand total (aggregates with no grouping) over fewer learners than the threshold is withheld the same way. Datasets without learners (authoring, ai_usage, audit) are not withheld.

This protects the output of one report. It does not stop a person who may run row-level reports from reading individual rows, and it cannot stop two different queries from being subtracted from each other: who may see learner data at all is decided by the dataset’s permission.

A saved report is a name, a description and a definition. POST /api/admin/reporting/saved (permission reporting_create, administrators; the saver must also hold the permission of the dataset) stores it:

Terminal window
ulams reporting save --input @report.json

with name, optional description, definition, and visibility: private (the default: the owner, and administrators who hold reporting_manage) or roles with shared_roles naming roles of this academy (for example tutor). Everyone who holds one of those roles and the permission reporting_read then sees the report in GET /api/admin/reporting/saved.

Sharing shares the definition, not the data. A report always runs with the permissions and scope of whoever runs it. A tutor who opens a report an administrator shared sees only what the dataset’s baseQuery allows that tutor, and a person without the dataset’s permission gets “you cannot run this report” (403; the list marks it runnable: false). Small groups are withheld the same way for every viewer.

Only the owner (who still holds reporting_create) or an administrator with reporting_manage changes or deletes a report. Deleted reports are kept out of every list. When a dataset is removed or renames a column a saved report uses, the report is not silently wrong: the list and GET /api/admin/reporting/saved/{id} show needs_repair: true with the problems by path, and running it answers 409 until it is fixed.

GET /api/admin/reporting/saved/{id}/run?format=json|csv|jsonl runs the report as the caller:

Format Answer
json (default) like the query preview: columns, at most 500 rows, meta
csv every row up to 1 000 000 (reporting.export_rows) as a stream: UTF-8 with a BOM, text that a spreadsheet could read as a formula gets an apostrophe
jsonl the same rows as JSON lines; a withheld group is a row with "_withheld": true and empty figures
xlsx an Excel workbook with one sheet: the column labels as a bold, frozen header row with a filter, numbers and booleans as typed cells, text as text (a cell that starts with = is never a formula). An Excel sheet holds 1 048 575 data rows, so a longer report is cut there

Every CSV and JSON lines export is recorded with who ran it, the dataset, the definition, the saved report, the number of rows and the route it left by (download). The record is the same compliance_exports log the compliance export uses.

POST /api/admin/compliance/schedules (permission compliance_report) takes saved_report_id instead of dataset, with name, frequency (daily, weekly, monthly, always at 06:00), recipient_ids (users of this academy) and a format of csv, jsonl or xlsx (XLSX is for saved reports only). The report must be one you can see, and it must not need repair.

The report is run once per recipient, with that recipient’s own permissions and scope, in one queued job each, and the file is mailed to that person: two people can get different rows from the same schedule. Every run is recorded as an export (channel schedule, the recipient, the saved report). A recipient who cannot run the report (they lost the dataset’s permission, have no e-mail address, no longer exist) is skipped, and the person who created the schedule gets a mail that names who was skipped and why; skipped_recipient_ids on the schedule lists them. If the saved report was deleted nobody gets a file and the owner is told the same way. Existing schedules on a compliance dataset are unchanged.

The same report builder is a set of CLI commands and, in the MCP toolset analytics (ulams mcp --toolsets analytics), eight tools named from the command (reporting.run is reporting_run):

Command Tool Does
ulams reporting datasets reporting_datasets the datasets and every column with what it allows
ulams reporting query --file def.json reporting_query a preview of a definition (a file, or inline for an agent)
ulams reporting list, show <id> reporting_list, reporting_show saved reports you can see
ulams reporting run <id> --format json|csv|jsonl|xlsx [--out file] reporting_run run a saved report with your permissions
ulams reporting save --name ... --file def.json [--role tutor] reporting_save save a definition, private or shared
ulams reporting update <id> [--feed on] reporting_update change a report; the feed switch needs reporting_manage
ulams reporting delete <id> reporting_delete delete (destructive: a plan and a confirm token first)

The reads (datasets, query, list, show, run) work with --read-only. The descriptions an agent reads say that the figures are the academy’s own measurements and that withheld groups are withheld on purpose, so an agent does not try to recover them. The result keeps the report’s own meta (mode, total_rows, withheld_groups, min_group_size).

A saved report can be offered as a read-only OData v4 feed to Excel, Power BI and Tableau, with a token limited to that one report; Looker Studio, Metabase and Superset read the CSV. See Connect a BI tool.

The report builder endpoints (datasets, query, saved reports and their runs) and the compliance report, its export and the compliance schedules belong to the reports token area: a scoped token needs reports:read (or reports:write to change schedules). Before this release the compliance report and schedules were under certificates; a token that was created for them with only certificates:read now needs reports:read as well. The rest of the compliance API (assignments, paths, rules, competencies, the dashboard) stays under certificates.