# Format response

If your tool returns complex, unstructured, or excessive information, you can format the response before passing it to the AI model. This helps improve the accuracy of the AI’s responses.

You can format the response by writing JavaScript code that modifies the tool’s output. Simply enter your code into the editor, and it will execute once the tool has run successfully.

The tool's response is accessible through the **`response`** variable, which is always a string. If you expect a JSON object, you’ll need to parse it first.

Once you've formatted the response, ensure you return it as a string to achieve the best results.

<figure><img src="/files/xS9P3uEO97h795NUo3Ce" alt=""><figcaption><p>Example code how to format the response of the weather tool</p></figcaption></figure>

### Tip

To ensure the AI model can process the response accurately and effectively.  We encourage you to follow these tips:

* **For simple data:** Return it as a string that clearly explains the data and its fields.
* **For complex data:** If the data cannot be easily formatted into a string, include a description explaining how the AI model should interpret it. Then, return both the description and data as a single string.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.chathive.app/tools/format-response.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
