/n8n-tutorials

How to send user metadata along with prompts to Gemini from n8n?

Learn how to send user metadata with prompts to Gemini from n8n using a simple, secure workflow that enhances context and personalization.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free consultation

How to send user metadata along with prompts to Gemini from n8n?

You send user metadata to Gemini from n8n by adding it directly into the JSON you send in the HTTP Request node that calls the Gemini API. Gemini supports arbitrary metadata via the generationConfig or system\_instruction fields, or by just embedding it as part of the contents data. n8n does not restrict what JSON you send, so you simply include metadata in the request body along with the prompt.

 

What this looks like in practice

 

In real n8n workflows, you typically:

  • Collect the user metadata (from a webhook, database query, form submit, etc.).
  • Merge it with the prompt in a Set node or by using expressions inside the HTTP Request node.
  • Send everything together as JSON to Gemini’s Generative Language API.

Gemini accepts extra fields without complaint as long as the required fields (contents) are valid. This is the easiest and most stable way to attach metadata for downstream logging, auditing, context control, or user‑specific behaviors.

 

A clean, safe way to send metadata

 

Below is a fully valid request body you can use inside an n8n HTTP Request node (POST → https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent). It embeds metadata in a custom field userMetadata, and also shows the normal Gemini contents block.

 

{
  "userMetadata": {
    "userId": "{{$json.userId}}",
    "plan": "{{$json.plan}}",
    "language": "{{$json.language}}"
  },
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "{{$json.prompt}}"
        }
      ]
    }
  ],
  "generationConfig": {
    "temperature": 0.7
  }
}

 

This works because Gemini’s API does not reject unknown top-level fields. n8n will replace the expressions like {{$json.userId}} with actual data from previous nodes.

 

Alternative: Put metadata inside the system instruction

 

If you want Gemini to actually use the metadata in reasoning (for personalization, policy, etc.), put it in system\_instruction. This is fully supported and production-safe:

 

{
  "system_instruction": {
    "role": "system",
    "parts": [
      {
        "text": "User metadata:\nUser ID: {{$json.userId}}\nPlan: {{$json.plan}}\nLanguage: {{$json.language}}"
      }
    ]
  },
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "{{$json.prompt}}"
        }
      ]
    }
  ]
}

 

This makes the metadata visible to the LLM itself, which is sometimes necessary (e.g., enforcing per‑plan rules or personalizing tone).

 

How to prepare the metadata cleanly in n8n

 

  • Use a Set node to structure the user data cleanly. This prevents messy nested JSON or broken expressions.
  • If metadata comes from a webhook, check its format using an If node before sending to Gemini so you don’t break the HTTP request.
  • If metadata is optional, wrap the expression with {{$json.fieldName || ""}} so the JSON body never fails.

 

Important production notes

 

  • Gemini’s API does not enforce strict schemas, so adding metadata fields is safe.
  • Be mindful of personally identifiable information (PII). If sending real user IDs, ensure secure storage of credentials and HTTPS is enabled.
  • If using n8n Cloud or Webhook trigger, sanitize incoming inputs before injecting them into prompts or metadata.

The core idea is simple: you send metadata by including it in the JSON body of your Gemini API call from the HTTP Request node. n8n lets you freely structure the JSON, and Gemini gracefully accepts and forwards any extra fields.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022