For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 response and context bloating.

You can format the response by writing JavaScript code that modifies the tool’s output. Write 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.

Example code how to format the response of the weather tool

Variables

We provide three string variables:

  • Response: A stringified output returned by the tool.

  • Session: A stringified JSON object containing session metadata:

  • Parameters: A stringified JSON object containing all parameters passed to the tool.

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.

Last updated