How to force AI Agent to output JSON and add information to it?

Hi, as practice to working with N8N I thought I create a workflow that reads the RSS feed from my favorite website, ask AI to generate a max 200 word summary of the “content” field found in the RSS JSON. Then from the output generate html and send an email. The html should of course take the summary but also use the author field, pubdata field and link field from the json.

Describe the problem/error/question

The problem I have is that the AI doesn’t generate nicely formatted json. It does generate a summary, but merges it with some of the fields into a big text. I’ve add a structured output parser but that either reports errors “Model output doesn’t fit required format” or outputs completely unwanted json.

What is the error message (if any)?

Model output doesn’t fit required format

Please share your workflow

Share the output returned by the last node

Ideally I’d get a json with these fields: summary (generated bij AI), title, author, pubdate taken from the RSS. I think I need this to generate nice html email.

Information on your n8n setup

  • n8n version:

1.119.1 - self hosted

  • Running n8n via (Docker, npm, n8n cloud, desktop app):

docker

Hi @Gabrie the structured output parser is the correct path, if you enable the auto-fix option on the parser this should allow a separate model to make sure that the output of your agent is formatted correctly. This is an option within the structured output parser and should get rid of any “doesn’t fit required format” errors you’re experiencing!

Hi @mike_chuckles, Thank you for your reply, but I still can’t get it to work. Immediately get “Error in sub-node ‘Structured Output Parser‘“. I tried with just enabling the auto-fix. Also tried with auto-fix plus dragging the fields coming from the AI into the auto-fix, but the same error.

Could I bother you to maybe load my json and correct it? I find very little specific documentation on how to work with this.
Thanks
Gabrie

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.