> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openserv.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Validate and improve output

> Use shadow-agent validation for difficult, high-value tasks.

<Frame>
  <img src="https://mintcdn.com/openserv/wCXyJJTiOX6drWSJ/images/tutorials/shadow-agent.webp?fit=max&auto=format&n=wCXyJJTiOX6drWSJ&q=85&s=472110d2aac11b6938efdd6819487978" alt="A draft answer entering a validation and revision loop" width="1536" height="1024" data-path="images/tutorials/shadow-agent.webp" />
</Frame>

Add `serv_shadow_agent` when an incorrect answer costs more than an additional validation call.

## What the shadow agent does

The normal model first produces a draft. SERV then asks a validator to judge that draft against the original request. If the draft fails, SERV asks the model to revise it and validates the new draft, up to the configured iteration limit.

The caller receives the final draft. SERV records whether it passed unchanged, was corrected, exhausted its attempts, or could not be validated. It does not expose the validator as a tool call to your application.

```js theme={null}
const response = await client.chat.completions.create({
  model: "gpt-5.4-mini",
  messages: [
    { role: "system", content: "Give careful recommendations and state missing information." },
    { role: "user", content: "Is now a good entry point for ETH?" },
  ],
  tools: [{
    type: "function",
    function: {
      name: "serv_shadow_agent",
      parameters: {
        type: "object",
        properties: {
          hint: { type: "string", default: "State what information is missing." },
          max_iterations: { type: "integer", default: 3 },
        },
      },
    },
  }],
});
```

The validator can revise a draft and retry it. It works with non-streaming requests only. See [SERV Tools](../tools) for defaults and limits.

## Configure the validator

`hint` adds task-specific criteria to the default meaningful-and-valid check. Make it observable and testable, such as “the answer must include the account ID” or “the recommendation must state missing information.” Avoid vague hints like “be better.”

`max_iterations` defaults to `3` and accepts values from `1` to `10`. More attempts can improve difficult outputs, but increase latency and cost. Start with the default and raise it only when your evaluation data justifies the expense.

Because the validator sees the original task context, keep the important requirements in the system prompt and user request. Validate structured data in your application as well.
