Get an API key
McpClient

sanitizeSchema()

sanitizeSchema(schema) → object

A tool's schema reduced to what model providers actually accept. Pure, exported, and not optional — a raw schema can fail a whole turn.

pure5 levels deepnever returns nothing
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

import { sanitizeSchema } from "iagenify";

const safe = sanitizeSchema(tool.inputSchema);
from iagenify import sanitize_schema

safe = sanitize_schema(tool["inputSchema"])

Why it is required

A refused schema fails the turn, not the tool

A provider that will not parse one construct refuses the request outright — so every answer in that conversation stops, not just the call that would have used it. One third-party server could break an entire agent.

What it does

  • Keeps the constructs providers understand and drops the rest.
  • Stops at five levels of nesting; deeper becomes a string.
  • Turns a schema with no usable type into a string parameter.
  • Never returns nothing — a parameter the model fills as text beats a tool that cannot be declared at all.

It is lossy on purpose

A deeply nested object becomes a string the model writes as text, which the server then parses. Less precise than the original, and declarable — which is the only comparison that matters.

api.mcp has already done it

tools() and the engine's own path both sanitise. Reach for this only when you are building declarations from listTools() yourself.

Pure, so testable

No network, no state, no surprises — which is what lets a change to it be checked against real schemas rather than hoped about.