Ibrahim Masalha
Ibrahim Masalha

Reputation: 31

Force AWS Bedrock Agent to provide JSON as answer

I am setting up a Bedrock Agent which has to take a user input, enrich it with the data held by a knowledge base and produce as output a JSON which will be then passed to a series of function collected in a library which has been developed for the purpose.

I do NOT want the agent to use action groups or trigger any Lambda. I want the agent to hold track of the sessions' conversation -> main reason why I am using an agent instead of simply calling a foundation model attached to knowledge base is memory: my app is stateless so the agent has to be the stateful part.

In the instruction the agent is told how to produce the json and he executes well this part. The issue is that sometimes when he has all the data needed to produce the json, he prints the json together with some sentence which breaks my flow of execution.

QUESTION: Do you know how I can force the Agent to ALWAYS output ONLY a JSON?

I tried through the instruction set and also tweaking a little bit the advanced prompts (post-processing and orchestration templates) but didn't get the result.

P.S. this behaviour affects about 40% of the conversations (just 10 tries done but still not a good result)

Upvotes: 3

Views: 418

Answers (0)

Related Questions