Skip to main content
Glama

patrol_duckdb

Checks date-partitioned DuckDB fact tables for data-quality incidents, tests proposed fixes against source control totals on a copy, and flags issues safe to auto-fix or needing escalation.

Instructions

Check a fact table in a DuckDB database for data-quality incidents and say which are safe to fix. A patrol checks every daily partition of the fact table for duplicate keys, duplicate rows, missing partitions, rows that point to no reference record, null spikes, and row counts or amounts that do not match the source's control totals. For each problem it proposes a fix, tests that fix on a copy against the control totals, and decides: "auto-fixed" (proven and low risk), "no action needed" (checked, the data is right) or "escalate" (a person must decide).

Use this before trusting, querying or building on a date-partitioned table that lives in a DuckDB
database, or after a load or pipeline change to confirm the data is still right. Use patrol_files
instead when the data is in CSV, TSV or Parquet files. Use run_demo to see the output on sample data.

Behavior: The database is opened read-only. Your data is never modified and nothing is written back. The only side effect is
writing four report files to out_dir: dashboard.html, audit.jsonl, incidents.csv, fixed_version.csv
(the proposed corrected table, for review). Runs locally with no network calls;
usually a few seconds, longer for tables with millions of rows. Fails with a readable error if a
file, table or mapped column does not exist; the error lists the columns that are available.

Returns the counts (incidents, auto_fixed, no_action_needed, escalate), needs_a_person (the escalated
incidents), all_incidents (partition, problems, decision, proposed_fix, residual for each) and
outputs (paths to the report files). Pass outputs.folder and a partition to get_incident for the
full evidence behind one decision. Tell the user about every escalated incident.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "db": "<db>",
      "table": "<table>",
      "ref_table": "<ref_table>",
      "manifest_table": "<manifest_table>"
    },
    "name": "patrol_duckdb"
  }
}

Input Schema

NameRequiredDescriptionDefault
dbYesPath to the DuckDB database file. Opened read-only.
keyNoColumn in the fact table that uniquely identifies a row (the primary key).txn_id
dateNoDate column the fact table is partitioned by, one partition per calendar day. The control totals must have a column with the same name.txn_date
tableYesFact table to check, optionally schema-qualified, for example gold.payments.
amountNoNumeric amount column in the fact table. It is compared with the 'amount' control total.amount
out_dirNoFolder to write the report files into. Created if missing; report files already there are overwritten. Omit to use a new temporary folder; its path comes back in outputs.folder.
ref_keyNoColumn in the reference table that the fact table's reference column must match.customer_id
segmentNoColumn that splits each day into segments, for example channel or region. The control totals must have a column with the same name, where '*' means the whole day.channel
categoryNoOptional categorical column in the fact table. Omit if the table has none.
ref_tableYesReference table that fact rows point to, for example customers.
referenceNoColumn in the fact table that points to the reference table (the foreign key).customer_id
thresholdNoGate threshold: the largest relative gap to the control totals that a verified fix may leave and still be marked auto-fixed (0.01 = 1%). Lower is stricter. Omit for the benchmark-calibrated default, 0.0135.
manifest_tableYesTable of the source system's control totals, one row per date and segment, with columns: the date column, the segment column ('*' = whole day), n (row count) and amount (sum).

Output Schema

NameRequiredDescriptionDefault
noteYes
tableYes
outputsYes
escalateYes
incidentsYes
auto_fixedYes
rows_checkedYes
all_incidentsYes
gate_thresholdYes
needs_a_personYes
no_action_neededYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed14 schema fields changedv0.4.2
    • addedInput schema / properties / amount / description
      Added value: +"Numeric amount column in the fact table. It is compared with the 'amount' control total."
    • addedInput schema / properties / category / description
      Added value: +"Optional categorical column in the fact table. Omit if the table has none."
    • addedInput schema / properties / date / description
      Added value: +"Date column the fact table is partitioned by, one partition per calendar day. The control totals must have a column with the same name."
    • addedInput schema / properties / db / description
      Added value: +"Path to the DuckDB database file. Opened read-only."
    • addedInput schema / properties / key / description
      Added value: +"Column in the fact table that uniquely identifies a row (the primary key)."
    • addedInput schema / properties / manifest_table / description
      Added value: +"Table of the source system's control totals, one row per date and segment, with columns: the date column, the segment column ('*' = whole day), n (row count) and amount (sum)."
    • addedInput schema / properties / out_dir / description
      Added value: +"Folder to write the report files into. Created if missing; report files already there are overwritten. Omit to use a new temporary folder; its path comes back in outputs.folder."
    • addedInput schema / properties / ref_key / description
      Added value: +"Column in the reference table that the fact table's reference column must match."
    • addedInput schema / properties / ref_table / description
      Added value: +"Reference table that fact rows point to, for example customers."
    • addedInput schema / properties / reference / description
      Added value: +"Column in the fact table that points to the reference table (the foreign key)."
    • addedInput schema / properties / segment / description
      Added value: +"Column that splits each day into segments, for example channel or region. The control totals must have a column with the same name, where '*' means the whole day."
    • addedInput schema / properties / table / description
      Added value: +"Fact table to check, optionally schema-qualified, for example gold.payments."
    • addedInput schema / properties / threshold / description
      Added value: +"Gate threshold: the largest relative gap to the control totals that a verified fix may leave and still be marked auto-fixed (0.01 = 1%). Lower is stricter. Omit for the benchmark-calibrated default, 0.0135."
    • changedOutput schema / (root)
      Previous value: -nullNew value: +{
      +  "$defs": {
      +    "Incident": {
      +      "properties": {
      +        "decision": {
      +          "title": "Decision",
      +          "type": "string"
      +        },
      +        "partition": {
      +          "title": "Partition",
      +          "type": "string"
      +        },
      +        "problems": {
      +          "items": {
      +            "type": "string"
      +          },
      +          "title": "Problems",
      +          "type": "array"
      +        },
      +        "proposed_fix": {
      +          "anyOf": [
      +            {
      +              "type": "string"
      +            },
      +            {
      +              "type": "null"
      +            }
      +          ],
      +          "title": "Proposed Fix"
      +        },
      +        "residual": {
      +          "anyOf": [
      +            {
      +              "type": "number"
      +            },
      +            {
      +              "type": "null"
      +            }
      +          ],
      +          "title": "Residual"
      +        }
      +      },
      +      "required": [
      +        "partition",
      +        "problems",
      +        "decision",
      +        "proposed_fix",
      +        "residual"
      +      ],
      +      "title": "Incident",
      +      "type": "object"
      +    },
      +    "Outputs": {
      +      "properties": {
      +        "audit_log": {
      +          "title": "Audit Log",
      +          "type": "string"
      +        },
      +        "dashboard": {
      +          "title": "Dashboard",
      +          "type": "string"
      +        },
      +        "folder": {
      +          "title": "Folder",
      +          "type": "string"
      +        },
      +        "incidents_csv": {
      +          "title": "Incidents Csv",
      +          "type": "string"
      +        },
      +        "proposed_fixed_version": {
      +          "title": "Proposed Fixed Version",
      +          "type": "string"
      +        }
      +      },
      +      "required": [
      +        "folder",
      +        "dashboard",
      +        "audit_log",
      +        "incidents_csv",
      +        "proposed_fixed_version"
      +      ],
      +      "title": "Outputs",
      +      "type": "object"
      +    }
      +  },
      +  "properties": {
      +    "all_incidents": {
      +      "items": {
      +        "$ref": "#/$defs/Incident"
      +      },
      +      "title": "All Incidents",
      +      "type": "array"
      +    },
      +    "auto_fixed": {
      +      "title": "Auto Fixed",
      +      "type": "integer"
      +    },
      +    "escalate": {
      +      "title": "Escalate",
      +      "type": "integer"
      +    },
      +    "gate_threshold": {
      +      "title": "Gate Threshold",
      +      "type": "number"
      +    },
      +    "incidents": {
      +      "title": "Incidents",
      +      "type": "integer"
      +    },
      +    "needs_a_person": {
      +      "items": {
      +        "$ref": "#/$defs/Incident"
      +      },
      +      "title": "Needs A Person",
      +      "type": "array"
      +    },
      +    "no_action_needed": {
      +      "title": "No Action Needed",
      +      "type": "integer"
      +    },
      +    "note": {
      +      "title": "Note",
      +      "type": "string"
      +    },
      +    "outputs": {
      +      "$ref": "#/$defs/Outputs"
      +    },
      +    "rows_checked": {
      +      "title": "Rows Checked",
      +      "type": "integer"
      +    },
      +    "table": {
      +      "title": "Table",
      +      "type": "string"
      +    }
      +  },
      +  "required": [
      +    "table",
      +    "rows_checked",
      +    "incidents",
      +    "auto_fixed",
      +    "no_action_needed",
      +    "escalate",
      +    "gate_threshold",
      +    "needs_a_person",
      +    "all_incidents",
      +    "outputs",
      +    "note"
      +  ],
      +  "title": "PatrolSummary",
      +  "type": "object"
      +}
  2. First observedv0.1.0

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well beyond the annotations: the database is opened read-only with no modification to data, and the only side effect is four named report files in out_dir (including a proposed corrected table), which explains why readOnlyHint is false despite the read-only database. It also discloses local-only execution, expected runtime and its scaling, and the shape of failure messages including that available columns are listed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the what and when, then clearly separated Behavior and Returns blocks; nearly every sentence carries information an agent needs (side effects, failure modes, decision vocabulary). It is long, and the three-way decision definitions are repeated in the Returns counts, so it is slightly padded but still well structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 13-parameter tool it covers everything an agent needs: what is checked, the decision semantics, side effects and file names, runtime, error behavior, and the escalation instruction. The output schema exists and the description still summarizes the returned fields and points to get_incident for evidence, so nothing material is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so all 13 parameters including manifest_table's required columns and threshold's default of 0.0135 are already documented in the schema. The description adds only a little adjacent meaning (the four files in out_dir, the partition key needed for get_incident) and never explains key/date/segment interplay, so baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and scope: check every daily partition of a fact table in DuckDB for named data-quality problems and classify each as auto-fixed / no action needed / escalate. The enumerated problem classes (duplicate keys, duplicate rows, missing partitions, orphan references, null spikes, control-total mismatches) make it unmistakable what this does and separate it from patrol_files.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit triggers (before trusting/querying/building on a date-partitioned DuckDB table, or after a load or pipeline change), a named alternative with the condition that selects it (patrol_files for CSV/TSV/Parquet), a demo option (run_demo), and a follow-up route (pass outputs.folder plus a partition to get_incident).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools