# Table aggregate check

`table-aggregate-check` · version 1.0.0 · CSV & tables · free, no key needed

Check claimed COUNT/SUM/AVG/MIN/MAX results over JSON rows exactly (SQL nulls); returns the first mismatch.

**Use when you need to: check claimed sum of a table column · verify count and total over json rows · check average min max claims against table data.**

## Decide before calling

Read the [versioned contract](/v1/tools/table-aggregate-check/versions/1.0.0) and the supported scope below. Reuse `table-aggregate-check@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `table-aggregate-check@1.0.0` for check claimed sum of a table column. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- check claimed sum of a table column
- verify count and total over json rows
- check average min max claims against table data
- did the agent compute the column total correctly
- verify sql aggregate results with null semantics
- exact rational sum check for decimal column
- בדיקת סכום וממוצע של עמודה בטבלה

## Not supported

- producing a report or chart of the aggregates
- GROUP BY results (use table-groupby-check)
- COUNT(DISTINCT) claims (use table-count-distinct-check)
- floating-point cells or approximate tolerance comparisons
- string MIN/MAX under a collation

## Behavior

- Implements ISO/IEC 9075-2:2023 (SQL:2023) set functions and grouping, r58 JSON-rows profile 1.0.0; every result carries reference_version.
- A row is a JSON object; a column absent from a row is the SQL null value. Cells are null, boolean, string or safe integer; non-integer JSON numbers are rejected (write decimals as strings).
- count_star counts rows; count counts non-null cells; sum, avg, min and max ignore nulls and return null when no non-null cell exists (SQL:2023 10.9), so sum of an empty table is null, not 0.
- sum, avg, min and max read safe integers and decimal strings (-?(0|[1-9][0-9]*)(.[0-9]+)?) as exact rationals; any other non-null cell (boolean, other string) is invalid_input non_numeric_value. avg is the exact rational sum/count.
- A claimed value is null or a string: integer, p/q fraction or decimal; it is compared by exact value, so "0.5", "1/2" and "2/4" are equal. computed is the reduced canonical form "n" or "n/d".
- All claims are parsed and every referenced numeric column is type-checked over all rows before any comparison; then claims are compared in input order and the first mismatch is reported (reason <function>_mismatch).
- claims_checked is the number of claims compared: all of them when valid, index + 1 of the first mismatch otherwise.

## Input

- `rows` (array of object, required): max items 10000
- `claims` (array of object, required): min items 1; max items 64

## Output

- `valid` (boolean, required)
- `reason` (one of null, "count_star_mismatch", "count_mismatch", "sum_mismatch", "avg_mismatch", "min_mismatch", "max_mismatch", required)
- `first_discrepancy` (object or null, required)
- `claims_checked` (integer, required): min 0
- `reference_version` (constant "ISO/IEC 9075-2:2023 (SQL:2023) set functions and grouping, r58 JSON-rows profile 1.0.0", required)

## Limits

- max input bytes: 1048576
- max rows: 10000
- max columns per row: 64
- max claims: 64
- max numeric chars: 64
- max value chars: 128

## Example

Request input:

```json
{
  "rows": [
    {
      "city": "San Francisco",
      "temp_lo": 46
    },
    {
      "city": "San Francisco",
      "temp_lo": 43
    },
    {
      "city": "Hayward",
      "temp_lo": 37
    }
  ],
  "claims": [
    {
      "function": "max",
      "column": "temp_lo",
      "value": "46"
    },
    {
      "function": "count_star",
      "value": "3"
    }
  ]
}
```

Response:

```json
{
  "result": {
    "valid": true,
    "reason": null,
    "first_discrepancy": null,
    "claims_checked": 2,
    "reference_version": "ISO/IEC 9075-2:2023 (SQL:2023) set functions and grouping, r58 JSON-rows profile 1.0.0"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "table-aggregate-check",
  "version": "1.0.0",
  "input": {
    "rows": [
      {
        "city": "San Francisco",
        "temp_lo": 46
      },
      {
        "city": "San Francisco",
        "temp_lo": 43
      },
      {
        "city": "Hayward",
        "temp_lo": 37
      }
    ],
    "claims": [
      {
        "function": "max",
        "column": "temp_lo",
        "value": "46"
      },
      {
        "function": "count_star",
        "value": "3"
      }
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/table-aggregate-check/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"rows":[{"city":"San Francisco","temp_lo":46},{"city":"San Francisco","temp_lo":43},{"city":"Hayward","temp_lo":37}],"claims":[{"function":"max","column":"temp_lo","value":"46"},{"function":"count_star","value":"3"}]}'
```

The machine-readable contract is at [/v1/tools/table-aggregate-check/versions/1.0.0](/v1/tools/table-aggregate-check/versions/1.0.0).

### CLI

```sh
node cli.mjs run table-aggregate-check 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Table count distinct check](/tools/table-count-distinct-check): Check a claimed COUNT(DISTINCT) and optional distinct-value list over JSON rows; returns the first mismatch.
- [Table join count check](/tools/table-join-count-check): Check a claimed inner, left, right or full equi-join row count over two JSON tables by key multiplicities.
- [Table groupby check](/tools/table-groupby-check): Check claimed GROUP BY rows (group keys and aggregate values) over JSON rows; returns the first wrong group or value.
- [Table reconciliation check](/tools/table-reconciliation-check): Check a claimed keyed reconciliation of two JSON tables and per-key statuses; report the first wrong key or count.
- [Table decimal group count](/tools/table-decimal-group-count): Count rows by exact string-valued dimensions with stable, bounded grouping output.
- [Table decimal group cube](/tools/table-decimal-group-cube): Sum exact decimal strings over deterministic SQL CUBE grouping sets with explicit subtotal markers.
