# sanitizeSchema()

Canonical URL: https://developers.iagenify.com/sdk/ref/mcp-client/sanitize-schema/
Language: en

`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.

Status: pure · 5 levels deep · never returns nothing

```javascript
import { sanitizeSchema } from "iagenify";

const safe = sanitizeSchema(tool.inputSchema);
```

## Why it is required {#why}

> **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 {#what}

- 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 {#lossy}

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 {#already-done}

[tools()](/sdk/ref/mcp/tools) and the engine's own path both sanitise. Reach for this only when you are building declarations from `listTools()` yourself.

## Pure, so testable {#pure}

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

- [listTools()](/sdk/ref/mcp-client/list-tools): Where raw schemas come from.
- [models.turn()](/sdk/ref/models/turn): Where the sanitised ones go.

```python
from iagenify import sanitize_schema

safe = sanitize_schema(tool["inputSchema"])
```
