I'm having issues with AI Agent, Structured Output Parser, and Download Image nodes in my n8n workflow for generating Instagram stories – errors like 'Invalid URL' and parsing failures

Hi everyone,

I’m building a workflow in n8n (Version 1.103.2) to generate Instagram stories from Google Sheets data, using GPT/Claude for content, Bannerbear for images, and uploading to Google Drive. However, I’m running into persistent errors in a few nodes, and I’ve tried several fixes but could use some community help.

Main Issues:

  1. AI Agent Node: Often fails with “Error in sub-node ‘Structured Output Parser’” – the model output doesn’t fit the schema (e.g., wrapped in “output” or violating length/hashtag rules). I’ve optimized the prompt and schema (added defaults, allowed additionalProperties), set “On Error” to “Continue (using error output)”, and added fallback code, but it still happens on some items.

  2. Structured Output Parser: Related to the above – model outputs sometimes have extra keys or invalid formats. Auto-Fix is enabled, but not always helping.

  3. Download Image1 Node (HTTP Request): Gets “Invalid URL” error when trying to download from Bannerbear’s image_url. The URL seems empty or malformed sometimes. I’ve added an IF-Node to check if it’s not empty and starts with “https://”, with a fallback branch, but the workflow still breaks occasionally.

What I’ve Tried:

  • Optimized AI prompt for strict JSON output (no wrappers, escapes, limits).
  • Updated schema with defaults (“” for missing fields), minItems:0 for hashtags, pattern tolerant for hashtags.
  • Added Code-Nodes for manual fixing (e.g., remove wrappers, truncate strings).
  • Set “On Error” to “Continue” in critical nodes.
  • Tested with single items (batch size 1 in Loop).
  • Checked credentials (OpenAI, Bannerbear, Google Sheets/Drive) – all valid.
  • Enabled debug logs, but no clear cause.

The workflow runs partially (e.g., up to Bannerbear), but fails on certain sheet rows. Here’s my full workflow JSON (imported from n8n):

[Click the </> button and paste your full JSON here from the initial message, e.g.:
{
“name”: “Instagram-stories-workflow”,
“nodes”: [ … ] // the entire JSON
}
]

Any ideas on how to make it more robust? Maybe better prompt/schema tweaks or Bannerbear polling? Thanks in advance!

Best,
Thomas




Hi @user,

The errors you’re encountering with the AI Agent, Structured Output Parser, and Download Image nodes often stem from mismatched response formats and URL handling. Here are some suggestions:

  1. Structured Output Parser:
  2. • Ensure your AI Agent node is returning valid JSON. Wrap your model prompt to explicitly return JSON, e.g.:
  3.  ```json
    
  4.  {  
    
  5.    "imageUrl": "<your_url>",  
    
  6.    "caption": "<your_caption>"  
    
  7.  }
    
  8.  ```  
    
  9. • In the Parser node, set the Schema to match these fields exactly and enable “Allow additional fields” if needed.
  10. Download Image Node:
  11. • Validate imageUrl before passing it in. Add an IF node to check the URL matches https?://.*\.(jpg|png).
  12. • If the URL is in base64, use the Function node to convert it back:
  13.  ```js
    
  14.  const data = items[0].json.imageBase64.replace(/^data:image\/\w+;base64,/, "");
    
  15.  return [{ json: { data } }];
    
  16.  ```  
    
  17. • Configure the Download node’s Binary Property correctly (e.g., data) and set the Response Format to Binary.
  18. Microservice-Based Hybrid Pattern:
  19. • Host your AI Agent and Parser as a separate service (Docker, serverless) exposing a REST/GPT endpoint.
  20. • In n8n, chain HTTP Request → JSON Parse → IF → Download Image. This decouples heavy parsing logic from n8n and improves resilience.
  21. • Use a robust storage backend (S3, Blob) for images instead of local temp files.
    By decoupling parsing, validation, and downloading into discrete nodes or external microservices, you’ll reduce parsing failures and invalid URL errors. Let me know if you need further examples or workflow snippets! :blush: