Tool-use with an array of objects paramter

I have a custom tool that calls some CRM API. The tool has a single parameter people with each record have the first name, last name, and email address of a person, like this:

[
   {email: "you@mail.com", firstname: "You", lastname: "LastName"},
   {email: "you2@mail.com", firstname: "You2", lastname: "LastName"},
   ...
]

If I put the array just like that as an "example" in the people parameter and call the tool manually (by triggering each node individually), it works properly. However, when the agent calls the tool, it fails.

Looking at the logs, it appears that it's formulating the argument correctly, at least I see an array of JSON objects in the logs that have the correct schema. But when I look at the CRM logs for the request, it appears that whatever is actually being passed into the people argument is an array of the correct size but the members of the array can't be correct (otherwise it would be working properly).

What's going on here?

Was able to see a little more - looks like it's creating an array of strings that each contain the object. Like this:

{"people":["{\"firstname\":\You\",\"lastname\":\"LastName\",\"email\":\"you@mail.com\"}",
  ...
]

Seems more like a model issue than a Retool one. Any tips to get this to always produce valid JSON?

Hey @JaredStufft,

You could create a function/workflow that first checks if the what was passed is an object, otherwise you can have a block that JSON parses it to obtain a proper object. After this block runs then you can make your API call.

I wouldn't try to enforce this to the llm as you'll never be 100% sure that it will do it on each instance, especially when there's a lot of data in the window context. Whereas if you put a safeguard in your function, you'll make sure the object is transformed even if the llm passes it as string.

1 Like