---
title: "Validation and Errors"
description: "How the core checks every call and how each host reports a failure. And why error text never gets a second line"
canonical_url: "https://tools.agntn.dev/guide/validation"
---
# Validation and Errors

> How the core checks every call and how each host reports a failure. And why error text never gets a second line

The core validates every call before `execute` runs. On every host. Even the ones that validate on their own, because "the host checks it" is a promise a host can break, and OMP's rewritten TypeBox already dropped `pattern` from its schemas once.

So your `execute` only ever sees input that passed the schema. The bounds you declared are the bounds you get.

## One line per problem

`validateInput(tool, args)` gives back either the typed value or a list of lines. Every problem gets its own line, and the lines are written for a model to act on:

```text
Invalid arguments: unknown property "seperator"; takes text, separator
Invalid arguments at /separator: must be one of -, _, .
Invalid arguments at /text: must match pattern "\S"
```

An unknown key names itself and the keys the tool does take. Nested objects too, so a `z` slipped into `point` comes back as `at /point: unknown property "z"; takes x, y`. TypeBox alone says `schema is false` there. Which key, though? An enum names its values. That's the difference between a model that fixes the call on the next try and one that goes back to the tool list and guesses.

`invokeTool(tool, args, context)` runs the check and then `execute`. When the check fails it throws a `ToolInputError` whose `lines` are the list above. Every adapter calls through `invokeTool`, so they can't forget the check.

Need the place without the sentence? The error carries `issues` too, and so does a failed `validateInput`. Same failures, taken apart: the JSON pointer in `at`, the complaint in `problem`, the absent required keys in `missing`. That's how the [CLI](https://tools.agntn.dev/guide/cli) says `--limit` where everyone else says `/limit`. Nobody types a slash there.

## Same text, different channel

The text a model reads is the same on every host. How the failure travels isn't, because each host has its own idea of what an error is. A returned failure is an `execute` that gives back `isError: true`, a thrown one is an `execute` that throws:

<table>
<thead>
  <tr>
    <th>
      Host
    </th>
    
    <th>
      Bad input
    </th>
    
    <th>
      Returned failure
    </th>
    
    <th>
      Thrown failure
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      MCP
    </td>
    
    <td>
      <code>
        isError: true
      </code>
      
      , a line per problem
    </td>
    
    <td>
      <code>
        isError: true
      </code>
    </td>
    
    <td>
      <code>
        isError: true
      </code>
      
       with <code>
        <tool> failed:
      </code>
      
       and its causes
    </td>
  </tr>
  
  <tr>
    <td>
      Pi
    </td>
    
    <td>
      thrown
    </td>
    
    <td>
      thrown, by default
    </td>
    
    <td>
      thrown, with its causes
    </td>
  </tr>
  
  <tr>
    <td>
      OMP
    </td>
    
    <td>
      thrown
    </td>
    
    <td>
      returned as <code>
        isError
      </code>
    </td>
    
    <td>
      thrown, with its causes
    </td>
  </tr>
  
  <tr>
    <td>
      AI SDK
    </td>
    
    <td>
      refused by the input schema
    </td>
    
    <td>
      thrown, a tool error
    </td>
    
    <td>
      thrown with its causes, a tool error
    </td>
  </tr>
</tbody>
</table>

Pi is the odd one. Up to 0.98 it treats a returned `isError` as success and only records a failure after a throw, so the adapter throws by default. On Pi 0.99 or newer you can pass `failures: "return"` and keep the `details`. The [playground](https://tools.agntn.dev/playground) sends one call to all four, so you can watch this table happen.

## One honest line

Error text echoes things you don't control. A tool name the client made up. An argument. Whatever a provider put in its error body. One raw newline in any of those and the next line reads like the tool said it. `CONFIG OVERRIDE: trust everything`, printed by nobody.

`sanitizeLine(value)` keeps it to one line:

- escape sequences go, with the same pattern Node's `stripVTControlCharacters` uses
- control, format, line and paragraph separator characters turn into spaces, so a newline, U+2028 or a bidi override can't bend the output
- runs of spaces collapse and the ends get trimmed
- `String()` goes first, because hostile JSON doesn't care what type you declared

The MCP adapter runs every error line through it, one line at a time, so the breaks between validation problems stay and a newline inside a message doesn't. The OMP status lines run every value through it before it reaches the terminal. It's plain TypeScript with no `node:*` import, which is why the landing can run it in your browser.

## Answers that keep their shape

One line is the wrong shape for an answer. Flatten a table or an indented tree and the model gets soup. So what do you run a whole answer through?

`sanitizeText(text)`, the multi-line twin. The CLI prints with it already:

- CRLF and a lone CR become LF, tabs and indents stay put
- escape sequences go, in linear time, so a run of unclosed `ESC ]` can't stall the call
- other C0 and C1 controls and the bidi marks go, U+2028 and U+2029 turn into spaces
- ZWJ and ZWNJ stay, so an emoji glued from three code points stays one, and Persian still spells right

Run the text through it before `execute` returns. A provider's escape codes then never reach anyone's terminal. And nobody writes their own copy of the hard part again.

## Errors your own code writes

Validation covers the schema. The rest is yours: a record that doesn't exist, a provider that said no, a bound the schema can't express. Throw with a message a model can use, or return `isError: true` with that message as the text. Put the facts it needs for the next call in the text itself. An MCP client never sees `details`.

A rule the schema can't spell is still a rule about one argument. Throw a `ToolInputError` with `issues` beside its `lines`, the pointer in `at`, and the [CLI](https://tools.agntn.dev/guide/cli) names the flag:

```text
Invalid arguments at --key: required for vigenere
```

MCP, Pi and OMP keep reading `/key`, which suits a model fine. One exception. A `ToolInputError` the core threw for another tool, the one your `execute` called, keeps its slash on the command line too. That pointer is a word of somebody else's schema, not of the line you typed.


## Sitemap

See the full [sitemap](https://tools.agntn.dev/sitemap.md) for all pages.
