How can I use a document (JSON) to guide AI writing style in my n8n workflow?

I have an n8n workflow that scrapes YouTube and Twitter for topic ideas, then uses multiple AI nodes to generate and write content.

I’d like to include a document (e.g. a JSON file with writing examples I like) and pass its contents to the AI node so it can mimic that style when writing.

What’s the best way to:

  • Upload or reference this document in the workflow?
  • Pass its contents as part of the AI prompt?

Thanks in advance!

Hey ATBV!
There are a couple ways to accomplish this depending on the project outcome you want.

My recommendation (easy, consistent):
In most projects, you want the content to be consistent. So the easiest way to accomplish this is to just reverse engineer the style and content guidelines you want ahead of time, and fine tune your system prompt in your AI nodes.
Just drop a couple of you favorite articles into your AI chat of choice and say “generate a system prompt that would create writing like this”, and then compare those results across the articles you like to tune it.

Idea #2 (still pretty easy, dynamic)
I’ve been using OpenAI mostly but assume you could do the same with other models. You can pass article contents as part of the AI prompt as additional prompts so that if you workflow is passing different articles based on context you can achieve the correct results.
Example:
{
“model”: “gpt-4o-mini”,
“messages”: [
{
“role”: “system”,
“content”: “You are a journalist writing for The New York Times. Maintain analytical, elegant prose consistent with NYT’s editorial style.”
},
{
“role”: “system”,
“content”: “Relevant style reference excerpts: {{input JSON variable}}”
},
{
“role”: “user”,
“content”: “Write an article about tattoos.”
}
],
“temperature”: 0.7,
“max_tokens”: 1200
}

Idea #3 (hard, maybe better results)
If you have a large number of articles you want as context, you could put them in a vector database, and with each query retrieve only the top 3ish documents that are relevant to the query to then insert into the AI node.

Hope this helps.

2 Likes

John, thanks so much for helping!

Ideas #2 and #3 sound the most interesting to me.

Before writing here, I tried to implement idea #2, but I could not figure out how to add the JSON variable to the AI node that generates content ideas. I have the JSON with my favorite articles ready.

Would you have a guide or a video on this?

For idea #3, are vector databases available as nodes in n8n?

I think you can just copy and paste is system prompt along with instruction on how yo use it.

If you can share your workflow I can provide more specific instructions.
The Json I provided would be for a Message a Model node. If you are inputting it to an agent you can use the article variable directly in the prompt, or have the articles available via the memory or tools nodes.
There are vector database nodes in n8n, again you would want to use these as the tool node for the Agent.

Let me share the workflow, im attaching images while i figure out how to embed a workflow in my response:

I want to add some good social media posts I want the AI agents to mimic somewhere in this workflow, probably somewhere near the content idea creator.

Edit: my workflow JSON code exceeds the response character limit in the reply box so I’m unable to paste the JSON

Workflow shown above!