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

# Tool results

> Evaluate OpenAI tool output before it is sent back to the model.

Tool results are untrusted input. Averta checks them before they re-enter the model loop.

## Responses API

For Responses API, tool results are `function_call_output` items.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const nextResponse = await client.responses.create({
    model: process.env.OPENAI_MODEL ?? "gpt-5.4-mini",
    input: [
      ...response.output,
      {
        type: "function_call_output",
        call_id: functionCall.call_id,
        output: JSON.stringify({
          matches: ["Password reset links expire after 24 hours."],
        }),
      },
    ],
    tools,
  });
  ```

  ```python Python theme={null}
  next_response = client.responses.create(
      model=os.environ.get("OPENAI_MODEL", "gpt-5.4-mini"),
      input=[
          *response.output,
          {
              "type": "function_call_output",
              "call_id": function_call.call_id,
              "output": '{"matches":["Password reset links expire after 24 hours."]}',
          },
      ],
      tools=tools,
  )
  ```
</CodeGroup>

The wrapper extracts the new `function_call_output` items and checks them before forwarding the continuation to OpenAI.

## Chat Completions

For Chat Completions, tool results are `tool` role messages.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const nextCompletion = await client.chat.completions.create({
    model: process.env.OPENAI_MODEL ?? "gpt-5.4-mini",
    messages: [
      ...messages,
      completion.choices[0]!.message,
      {
        role: "tool",
        tool_call_id: "call_123",
        content: JSON.stringify({
          matches: ["Password reset links expire after 24 hours."],
        }),
      },
    ],
    tools,
  });
  ```

  ```python Python theme={null}
  assistant_message = completion.choices[0].message.model_dump(exclude_none=True)

  next_completion = client.chat.completions.create(
      model=os.environ.get("OPENAI_MODEL", "gpt-5.4-mini"),
      messages=[
          *messages,
          assistant_message,
          {
              "role": "tool",
              "tool_call_id": "call_123",
              "content": '{"matches":["Password reset links expire after 24 hours."]}',
          },
      ],
      tools=tools,
  )
  ```
</CodeGroup>

## Block Behavior

If policy blocks the tool result:

* the wrapper throws `AvertaSdkError`
* the continuation request is not sent to OpenAI
* the model does not see the returned tool content

## Decision Callback

<CodeGroup>
  ```typescript TypeScript theme={null}
  client = wrapOpenAI(client, {
    onDecision(event) {
      if (event.checkpointType === "tool_result") {
        console.log(event.tool.name, event.decision.decision);
      }
    },
  });
  ```

  ```python Python theme={null}
  def on_decision(event):
      if event["checkpoint_type"] == "tool_result":
          print(event["tool"].name, event["decision"].decision)
  ```
</CodeGroup>

## Debugging

| Symptom                         | Check                                                                                          |
| ------------------------------- | ---------------------------------------------------------------------------------------------- |
| No tool-result decision         | Confirm the continuation contains only provider-native tool-result items for the current turn. |
| Tool result blocks unexpectedly | Inspect the returned content for prompt injection or unsafe instructions.                      |
| Tool name is missing in logs    | Confirm the original tool call was checked and has a stable `call_id`.                         |
