Atlas Commerce Operations — Analytical & Transactional Skill
Purpose
Complete a self-contained operational data task against the Atlas Commerce Operations
workplace. Each task provides a natural-language prompt, a business-request payload with
scope/definitions/rules, and an answer-template JSON that enforces the output schema.
Produce exactly one answer.json that matches the template with no extra keys or
narrative.
Input layout (every task)
input/
prompt.txt — natural-language task brief + constraints
payloads/
answer_template.json — exact output schema (required keys, types, enums, ordering)
<request>.json — business scope, definitions, rollups, policies, rules
Read all three files before touching the database.
Workplace API
| Endpoint | Method | Purpose |
|---|---|---|
/api/schema |
GET | Full DDL for every table + every index |
/api/data-dictionary |
GET | Column-by-column descriptions and conventions |
/api/sql |
POST | Read-only SQL (SELECT / WITH … SELECT) |
/api/sql/transaction |
POST | Write via statements[] + expected_total_changes |
/api/correction-audit |
GET | Read correction-audit records |
- Base URL: read from
environment_access.md(overrides any<TASK_ENV_BASE_URL>placeholder). - Auth:
Authorization: Bearer <token>fromenvironment_access.md. - POST /api/sql body:
{"sql": "<SQL>", "params": [<scalar…>]}. Use parameterised queries — never interpolate values into SQL text. - POST /api/sql/transaction body:
{"statements": [{"sql": "<SQL>", "params": [<scalar…>]}], "expected_total_changes": <int>}.expected_total_changesis the total rows the transaction must modify (insert + update + delete); the endpoint rejects the commit if the actual count differs.
Step-by-step method
1. Absorb the business ask
- Read
prompt.txt— extract the task type (analytical vs correction), deadlines/cutoffs, and any procedural constraints ("do not change data", "apply only the minimal correction"). - Read the
<request>.jsonpayload — capture:- Scope: date windows, account populations, regions, tiers, segments, campaigns, warehouse IDs, import-batch IDs.
- Definitions: what makes an entity eligible, complete, on-time, breached, a candidate, severe, etc. These are business-logic predicates.
- Rollups / rankings: aggregation levels, sort orders, tiebreaks, result-size limits.
- Policy / status rules: tiered classifications ordered from strictest to most permissive (evaluate in order, the first match wins).
- Rounding / precision: which final values to round and to how many decimal places.
- Read
answer_template.json— everyrequiredkey must appear in the output. Respecttype,enum,pattern,multipleOf,minItems/maxItems,uniqueItems,additionalProperties: false, and anyx-list-orderingannotations.
2. Understand the schema
- Call
GET /api/schemaandGET /api/data-dictionary. Map every entity in the business scope to concrete tables and columns. - Internalise these conventions (they apply to every table):
| Convention | Rule |
|---|---|
| Timestamps | ISO-8601 UTC text ending in Z |
| Dates | YYYY-MM-DD text |
| Money (minor) | Stored in the smallest currency unit (cents); divide to get major units |
| FX rates | fx_rates.usd_per_unit — multiply the minor→major converted value |
| Integer booleans | 0 = false, 1 = true |
| Canonical fields | Use canonical_* columns for analytics; raw_* columns are source values |
| Production filtering | accounts.is_internal = 0 AND accounts.is_test = 0 |
| Effective dedup | ROW_NUMBER() OVER (PARTITION BY source_system, external_event_id ORDER BY ingested_at DESC) = 1 |
| Stable identifiers | Primary-key columns (*_id, *_row_id) are the authoritative row identity |
3. Query the data
Read-only analytical SQL
- Start with CTEs that define the eligible population using the request scope.
- Filter early — apply time windows, account population, region, and segment filters in the innermost CTEs so every downstream step works on the smallest set.
- Dedup correctly — every imported table (
carrier_scans,refund_attempts,payment_events,case_events,order_events,warehouse_task_events,inventory_movements) needs the effective-dedup pattern. The dedup column tuple is always(source_system, external_event_id)withMAX(ingested_at)picking the winning row. - Use canonical fields for business logic. Raw fields are source-system values
that may contradict the canonical truth. The exception is task 003-style
contradiction detection: compare
raw_statusagainstcanonical_statusto find mismatched rows. - Time windows: when the request says inclusive of both boundaries, use
>= start AND <= end. When it says a cutoff, use<= cutoff. - Money in SQL: convert minor to major by dividing (e.g.
amount_minor / 100.0). For cross-currency conversions joinfx_ratesonservice_date = rate_date(orevent_atdate) and the row's currency, then multiply:(amount_minor / 100.0) * fx.usd_per_unit. - Aggregate with GROUP BY, then compute rates as fractions in the outer query. Round only the final reported numbers, not intermediate values.
Transactional SQL (correction tasks only)
A correction task has these signature elements in the request payload:
approved_correctionblock withreason_code,actor,audit_id,correction_key,corrected_atcorrection_status_ruledefiningAPPLIED/NOT_APPLIED
Correction procedure:
- Find the contradiction: query the raw vs canonical fields to identify exactly one row where they disagree.
- Plan the UPDATE: the correction changes only the canonical field to match the
source truth. The SQL is a single
UPDATEstatement with aWHEREclause that pins the exact row by its primary key. Set thecorrected_atandcorrection_reasoncolumns as well. - Plan the INSERT: insert one row into
correction_auditwith all the fields from the request'sapproved_correctionblock plus the actual entity/field/values. Required audit columns:audit_id,correction_key,entity_type,entity_id,source_row_id,field_name,old_value,new_value,reason_code,corrected_at,actor. - Submit the transaction:
POST /api/sql/transactionwith both statements andexpected_total_changesset to the sum of rows each statement should affect (typically 1 for the UPDATE + 1 for the INSERT = 2). The endpoint atomically commits or rejects. - Verify:
POST /api/sqla post-correction query to confirm the canonical value is now correct, ANDGET /api/correction-auditto confirm the audit row is present. - Report
APPLIEDonly when the transaction succeeded (no error response), exactly one business row and one audit row were committed, and the post-change query confirms the new value. Otherwise reportNOT_APPLIED.
4. Compute the answer
Translate each business definition into a concrete predicate:
| Definition pattern | SQL / processing approach |
|---|---|
| Count of distinct eligible X | COUNT(DISTINCT x_id) after filtering |
| X is complete when … | Per-entity condition aggregated across child rows; use HAVING or a CASE/BOOL_AND pattern |
| X is on-time when … | Compare delivered timestamps to promised timestamps |
| Rate = A ÷ B | Compute A and B as integers, divide, cast to REAL, round |
| Severe exception condition | Apply the 24-hour threshold rule after determining completeness/on-time status |
| Rank / top-N | ORDER BY … LIMIT N with explicit tiebreak columns |
| Tiered classification | Evaluate conditions top-to-bottom; first match wins |
| Median | For even counts average the two central values; use ORDER BY … LIMIT 1 OFFSET … or window functions |
- Round only final reported rates to the specified decimal places (use
ROUND(value, decimals)). - Sort arrays exactly as specified (ascending IDs, or rank-order with tiebreaks).
- Validate every output value against the template's
type,pattern,enum,minimum,maximum,multipleOf,minItems,maxItems.
5. Write the output
Write a single JSON object to answer.json in the working directory:
- Every key from the template's
requiredarray must be present. - No extra keys beyond what the template declares (
additionalProperties: false). - Numbers must satisfy any
multipleOfconstraint. - Strings must match any
patternregex. - Arrays must be within
minItems/maxItemsbounds, containuniqueItems, and be in the declared order. - The file must be valid JSON with no trailing text, commentary, or explanation.
Task-type quick reference
Analytical / Scorecard (most common)
- Read-only; never call
/api/sql/transaction. - The request payload defines cohorts, metrics, rollups, and status rules.
- Compute every metric from the database; do not infer or estimate.
- Typical output: counts, rates, ranked lists, status labels.
Reconciliation / Exposure
- Involves money: minor-unit conversion and FX rates.
- Leakage / candidate detection: compare values across related rows (e.g., refunds vs order gross) and apply multi-condition candidate rules.
- Reason ranking: aggregate by reason code, sort by net amount, apply tiebreaks.
Carrier Quality / Correction
- Find exactly one raw-vs-canonical contradiction.
- Execute a minimal UPDATE + audit INSERT via
/api/sql/transaction. - Verify the correction post-commit.
- Report pre- and post-correction backlog counts.
Warehouse Productivity
- Time-windowed task creation with a later state cutoff.
- Employee-level metrics: units per productive hour, completion rates.
- Team-level and facility-level aggregations with tiered status.
Support Health
- Case lifecycle analysis with SLA thresholds per priority.
- Active-time clock: time from open to first response, time from open to resolution.
- Breach detection: compare active time against priority-specific thresholds.
- Worst-account ranking by multi-column sort.
Guardrails
- Never skip the schema/dictionary calls — tables and columns are stable but the specific set available may vary. Always introspect before querying.
- Always use effective dedup on imported tables or you will double-count rows that were re-ingested.
- Always filter production accounts (
is_internal = 0 AND is_test = 0) unless the request explicitly says otherwise. - Always use canonical fields for business logic; raw fields are for contradiction detection only.
- Never change data on analytical tasks — use only
POST /api/sql. - Respect the answer template exactly — an extra field, a missing required field, a value outside an enum, or a number with wrong precision invalidates the answer.