Skip to main content
Glama

Verify a pandas rewrite

verify_rewrite
Read-onlyIdempotent

Check that a pandas rewrite produces the same output as the original and measure whether it is faster before recommending it.

Instructions

Check that a pandas rewrite gives the same result as the original, and measure whether it is faster.

Use this before telling the user a rewrite is equivalent or faster; use check_code to find candidates. Runs setup once, then original and candidate on separate copies of its variables, compares each output strictly (type, dtype, index, names, NaN positions, exact values) and times both (median of repeated runs, about 2 s budget).

Side effects: executes the given code locally. original and candidate must be pure computation (no file, network, subprocess or global-state calls, no unseeded randomness); otherwise nothing runs and refused says why. The verdict holds for these inputs only.

verdict is "identical"; "scalar_types" (every value equal, but some scalars differ in type, e.g. numpy.float64 vs float, listed in details.scalar_types; not identical); "within_tolerance" (floats differ by at most rtol, largest difference reported); or "different" (with where).

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": {
      "original": "<original>",
      "candidate": "<candidate>"
    },
    "name": "verify_rewrite"
  }
}

Input Schema

NameRequiredDescriptionDefault
rtolNoRelative tolerance for floats. Results that differ by no more than this get within_tolerance instead of different.
setupNoCode run once to build representative inputs, e.g. a DataFrame with realistic size and dtypes. It may read files and use seeded randomness. Leave empty if original builds its own inputs.
outputsNoNames of the variables to compare. Default: the variables original assigns.
originalYesThe pandas code to replace, e.g. an iterrows loop. It can use the variables setup creates.
candidateYesThe rewrite that should produce the same variables as original.

Output Schema

NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed6 schema fields changed
    • addedInput schema / properties / candidate / description
      Added value: +"The rewrite that should produce the same variables as original."
    • addedInput schema / properties / original / description
      Added value: +"The pandas code to replace, e.g. an iterrows loop. It can use the variables setup creates."
    • addedInput schema / properties / outputs / description
      Added value: +"Names of the variables to compare. Default: the variables original assigns."
    • addedInput schema / properties / rtol / description
      Added value: +"Relative tolerance for floats. Results that differ by no more than this get within_tolerance instead of different."
    • addedInput schema / properties / rtol / minimum
      Added value: +0
    • addedInput schema / properties / setup / description
      Added value: +"Code run once to build representative inputs, e.g. a DataFrame with realistic size and dtypes. It may read files and use seeded randomness. Leave empty if original builds its own inputs."
  2. First observedv0.1.1

TDQS

A4.6/5.0
Behavior4/5

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

Goes well beyond the annotations by disclosing that code is executed locally, that setup runs once and each candidate runs on separate copies of variables, that timing uses a median of repeated runs within a ~2 s budget, and that impure or unseeded code is refused with a reason in `refused`. The purity constraint (no file/network/subprocess/global-state calls) also reconciles the local execution with readOnlyHint=true. Minor gap: it does not say what happens on timeout or how large a speed difference is considered meaningful.

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 purpose and the when-to-use rule, then constraints, then verdict vocabulary — a sensible order. It is dense but nearly every sentence carries operational information; the enumerated verdict values are partly redundant with the output schema and are the main place where trimming would be possible.

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 code-executing comparison tool this covers everything an agent needs before calling: prerequisites about input purity, the meaning of setup, tolerance behavior, timing methodology, refusal handling, and the limits of the verdict. Return values are also covered by the output schema, so the description does not need to repeat them further.

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

Parameters4/5

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

Schema coverage is 100%, so the baseline is 3; the description adds real meaning on top by explaining the execution relationship between setup, original, and candidate (separate copies, setup runs once). It also ties rtol to a concrete outcome (within_tolerance with the largest difference reported), which clarifies the tolerance parameter's role in the verdict rather than just restating it.

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 object ('Check that a pandas rewrite gives the same result as the original') plus a second function ('measure whether it is faster'). It is clearly distinguishable from the sibling check_code, which is described as finding candidates rather than verifying them.

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 an explicit trigger ('Use this before telling the user a rewrite is equivalent or faster') and an explicit alternative ('use check_code to find candidates'). It also states a scope limit ('The verdict holds for these inputs only') that tells the agent when a passing result is not sufficient evidence.

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