Skip to main content
Glama

Confusion Matrix

confusion_matrix

Compute a confusion matrix from a trained model or your true and predicted labels, with optional normalization and the most confused class pair for error analysis.

Instructions

Confusion matrix as numbers (rows = true class, columns = predicted class), plus the most confused class pair and, for two classes, TN / FP / FN / TP. For a picture use confusion_matrix_plot. Use EITHER a trained classification model (model_id) OR your own lists of true and predicted labels. Args: model_id (str, optional): ID of a trained classification model. dataset (str): "test" or "train". Only used with model_id. Default is "test". normalize (str, optional): None for counts, "true" (each row sums to 1: recall per class), "pred" (each column sums to 1: precision per class) or "all" (whole matrix sums to 1). y_true (list, optional): True labels (use together with y_pred). y_pred (list, optional): Predicted labels, same length as y_true. Returns: dict: labels, matrix, most_confused and (binary) the TN/FP/FN/TP breakdown.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "confusion_matrix"
  }
}

Input Schema

NameRequiredDescriptionDefault
y_predNo
y_trueNo
datasetNotest
model_idNo
normalizeNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.7/5.0
Behavior4/5

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

No annotations are supplied, so the description carries the full behavioral burden, and it largely does: it discloses the exact return shape (labels, matrix, most_confused, binary TN/FP/FN/TP) and what each normalize mode does to the values. The remaining gap is edge-case behavior — what happens if both model_id and y_true are supplied, or neither, since zero parameters are required.

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

Conciseness5/5

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

Front-loaded with the core output and the alternative tool, then structured Args/Returns blocks. Every line carries information an agent needs — no restating of the title, no filler — and orientation plus binary caveat are stated in the first sentence rather than buried.

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

Completeness4/5

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

For a five-parameter tool with no output schema and no annotations, the description supplies the return structure and all parameter meanings, which is most of what is needed. It stops short of stating which arguments are required or what validation error occurs when the EITHER/OR contract is violated, which matters because the schema marks nothing as required.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must compensate, and it does for all five parameters: model_id, dataset (with the otherwise-undocumented "test"/"train" value set and its default), normalize (four modes with precise statistical meaning), and y_true/y_pred including the same-length constraint. This adds meaning well beyond the bare type declarations in the schema.

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+resource (compute a confusion matrix as numbers) and immediately pins down orientation (rows = true class, columns = predicted class), plus what extras come back (most confused pair, TN/FP/FN/TP for binary). It explicitly names the sibling it is not, confusion_matrix_plot, so an agent can separate the two without opening either schema.

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 routing rule to the alternative ("For a picture use confusion_matrix_plot") and states the two mutually exclusive input modes: EITHER model_id OR y_true/y_pred lists. The normalize option is described in terms of when to pick each value (row sums = recall, column sums = precision), which is usage guidance as much as parameter semantics.

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