i created the agent with param “response_model=CustomReq”, where CustomReq is a Pydantic class.
Agno does SOMETIMES parse the JSON returned by Perplexity, and create an object of that type. The problem is that Agno doesn’t work 100%.
In debug mode, I saw that perplexity returned a string like: json { ... }. This string is well-behaved JSON. but Agno just failed to parse it, and create the object.
The problem might be caused by Perplexity returning the extra string prefix “json" and the postfix "”, which causes Agno to refuse to parse the json string, thinking it’s badly-formed?
thanks for reaching out and supporting Agno. I’ve shared this with the team, we’re working through all requests one by one and will get back to you soon.
If it’s urgent, please let us know. We appreciate your patience!
Hi, Thanks for reaching out. I’m using Agno 1.1.7 (released Feb 26). And the problem i had is with the structured output, using Perplexity (sonar-pro model).
The response from Perplexity sometimes (mistakenly) has the json string surrounded by a Markdown code fence: triple backticks, then the string “json”, then the JSON string itself, then the closing triple backticks. This is perplexity’s bug. Even if i explicitly prompt it not to include this code fence, it sometimes sends back this.
Since I use structed output, Agno would try to run json.loads() function to convert it to a Python object, and the it would choke on this input string, as it has the markdown code fence.
Is there a way to check if this markdown code fence exists, and strip it before converting it to a Python object?