I have a workflow that invokes an agent and then takes the output and creates a record in a Retool database. Each record has an agent_output JSON field.
In the agent’s instructions, I specify that the output should be in JSON. I added a tool that converts the output into the same JSON schema. Yet the agent still returns a message in invokeAgent.data.
How can I enforce that the output format be in JSON? Otherwise, uploading the output to the retool database fails, as does the workflow run.
There are a couple ways to solve this, but the optimal one probably depends on what the agent is doing – can you share more about the agent’s goals & tools?
The goal is to source contacts. I pass through relevant information in the input, including the website, and give it tools to:
extractRelevantEmailsFromText
formatAgentOutputAsJson
Search Web
Get Webpage Content
MCP Server that can map websites
The output should include fields such as email, name, title, source_url, for each contact, in JSON. Only when an email is found. Once uploaded to the Retool database, I want to retrieve the contacts in a Retool dashboard table component, one row per contact, with the fields mentioned above.
@Jonathan_A, what about giving the agent the “insert into Retool database tool”? I think this will be much more reliable, and it should be able to accurately pass the result of extraction as JSON to the tool.
Just wanted to check if Kent's suggestion of using the “insert into Retool database” tool was able to solve this use case.
I just answered another thread about how Agents are not the best option for strictly enforcing output formatting. A better option for leveraging an AI to output strictly JSON would be an AI Action via query.
But if the Agent can insert directly into Retool consistently that should be fairly consistent, and if not let us know!