Ikerman
03/18/2025, 12:17 PMShubham Bajaj
03/19/2025, 1:54 PMresult field to be a properly formatted string without line breaks.
## Solution
Follow this format exactly when responding from your tool:
json
{
"results": [
{
"toolCallId": "call_VaJOd8ZeZgWCEHDYomyCPfwN",
"result": "{\"temperature\":62,\"condition\":\"partly cloudy\"}"
}
]
}
The key points to remember:
- Use JSON.stringify() on your JSON data for the result field
- Ensure there are no line breaks in the stringified JSON
- Make sure the toolCallId matches the original request ID
- Set async: false in your tool configuration
## Step-by-Step Implementation
1. Correctly format your server response:
javascript
app.post('/api/tools/weather', (req, res) => {
const { toolCallId, arguments: args } = req.body;
const parsedArgs = JSON.parse(args);
// Create your data object
const weatherData = {
temperature: 62,
condition: "partly cloudy",
location: parsedArgs.location
};
// Return the response with properly stringified JSON
res.json({
results: [
{
toolCallId: toolCallId,
result: JSON.stringify(weatherData) // This creates a single-line string
}
]
});
});
2. Example of correct response format:
json
{
"results": [
{
"toolCallId": "call_ABC123",
"result": "{\"data\":{\"key1\":\"value1\",\"key2\":\"value2\"}}"
}
]
}
This approach ensures that your tool correctly sends JSON data that Vapi can properly process, while maintaining compatibility with the API requirements.