AI Agent Tool Subworkflow not passing variables

Describe the problem/error/question

I have a main workflow with an AI Agent node that uses a subworkflow as a tool. I am passing a JWT from the parent workflow to the subworkflow. The JWT is evaluating CORRECTLY when viewing the execution of the parent workflow. When viewing the execution on the subworkflow, that same JWT being passed is malformed/dropping characters/truncating (with ..).

What is the error message (if any)?

401

Please share your workflow

This is the main workflow AI Agent tool node

{
  "nodes": [
    {
      "parameters": {
        "description": "Sends an email. Provide recipient_email, sender_email, subject, message_html, accessToken, emailRFCMessageId (original email's RFC Message-ID for threading), and emailThreadId (thread ID) parameters. Returns draft ID and message.",
        "workflowId": {
          "__rl": true,
          "value": "Z4AR7KUHGM7zfDPS",
          "mode": "list",
          "cachedResultUrl": "/workflow/Z4AR7KUHGM7zfDPS",
          "cachedResultName": "Email Send Tool"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "sender_email": "={{ $json.agentEmail }}",
            "recipient_email": "={{ $json.emailFrom }}",
            "subject": "={{ $fromAI('subject') }}",
            "message_html": "={{ $fromAI('message_html') }}",
            "accessToken": "={{ $(\"Webhook Trigger\").item.json }}",
            "agentEmail": "={{ $json.agentEmail }}",
            "emailProvider": "={{ $json.emailProvider }}",
            "emailThreadId": "={{ $json.emailThreadId }}",
            "bccEmail": "={{ $json.bccEmail }}",
            "emailRFCMessageId": "={{ $json.emailRFCMessageId }}",
            "outlookMessageId": "={{ $json.body.email.messageId }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "accessToken",
              "displayName": "accessToken",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "agentEmail",
              "displayName": "agentEmail",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "sender_email",
              "displayName": "sender_email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "recipient_email",
              "displayName": "recipient_email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "subject",
              "displayName": "subject",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "message_html",
              "displayName": "message_html",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "emailRFCMessageId",
              "displayName": "emailRFCMessageId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "emailThreadId",
              "displayName": "emailThreadId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "bccEmail",
              "displayName": "bccEmail",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "emailProvider",
              "displayName": "emailProvider",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "outlookMessageId",
              "displayName": "outlookMessageId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        -704,
        12096
      ],
      "id": "6e27ca16-3570-47ab-bb5b-e24d9ada5370",
      "name": "Call 'Send Email'"
    }
  ],
  "connections": {
    "Call 'Send Email'": {
      "ai_tool": [
        []
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "a60e669edf11e952ca807918abec0f36bdc555a18c8aa44a9b6d0ff9610266c0"
  }
}

This is the subworkflow start node

{
  "nodes": [
    {
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "accessToken"
            },
            {
              "name": "agentEmail"
            },
            {
              "name": "sender_email"
            },
            {
              "name": "recipient_email"
            },
            {
              "name": "subject"
            },
            {
              "name": "message_html"
            },
            {
              "name": "emailRFCMessageId"
            },
            {
              "name": "emailThreadId"
            },
            {
              "name": "bccEmail"
            },
            {
              "name": "emailProvider"
            },
            {
              "name": "outlookMessageId"
            }
          ]
        }
      },
      "id": "26e5056c-05dd-4165-b1a1-d386ced93852",
      "typeVersion": 1.1,
      "name": "Start",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -96,
        9728
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        []
      ]
    }
  },
  "pinData": {},
  "meta": {
    "instanceId": "a60e669edf11e952ca807918abec0f36bdc555a18c8aa44a9b6d0ff9610266c0"
  }
}

Share the output returned by the last node

The error output is obviously 401 Invalidated Auth token

Information on your n8n setup

  • n8n version: [email protected]
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system: MacOS

@matdak Hi and thanks for reaching out.

A couple of observations.

The truncation of the JWT (..) may be UI and expected behavior that it is being hidden from display.

The real issue is likely that the JWT is not being passed as a string varible but rather an object.

Change the accessToken mapping in the toolWorkflow node to whatever actually holds the JWT. Examples:

  • If it’s in the webhook body: ={{ $json.accessToken }} or ={{ $(“Webhook Trigger”).item.json.accessToken }}

you can validate the JWT passed to your tool workflow right after the Start node, add a temporary Code node (or Set node) with this:

const token = $json.accessToken;

return [{
  json: {
    type: typeof token,
    length: token?.length || 0,
    preview: token ? token.substring(0, 80) + "..." + token.slice(-60) : null,
    looksLikeJWT: token && token.includes(".") && token.length > 200
  }
}];

Run the full main workflow again > open the subworkflow execution > check the Code node output.

Let us know is this helps and if any issue encountered. (please don’t forget to mark as solution if this helps!)

2 Likes

Hey Jekylls, thanks for your reply!

I tried doing the mapping manually to the workflow trigger just by dragging and dropping the field (which should be a string) but kept getting undefined. In screenshot below I have the error execution pinned, and can get it to resolve with {{ $(‘Webhook Trigger’) }} which DOES evaluate to[Object], but anything further than that is undefined (like {{ $(‘Webhook Trigger’).item }}

1 Like

For more context:

In my previous execution you can see that {{ $json.body.accessToken }}is evaluating correctly to the full JWT (as evidenced by the scroll bar length)

However when looking at the subworkflow execution, you can see it abruptly stops (and the input type on the subworkflow is String

1 Like

@matdak I think the issue is the Auth Header on the request - as you’ve shown it does appear correct so you may need to understand if the API expects the token to be passed as Param or header. do you have a screenshot of the node attempting to send the API request with that accessToken please? - If not already try Authorization: Bearer {{ $json.accessToken }}

1 Like

Ok so I don’t know why this worked, but clicking Refresh Workflow input List on the Tool node got it to work.

Screenshot 2026-03-19 at 11.51.41 AM

This came from this other forum topic for a very similar issue: N8N data from main workflow not passing trough in subworkflow

I don’t know WHY this is the case. I’m assuming its just a byproduct of whatever funky stuff n8n + langchain is doing behind the scenes to wire this all up, and comes with the territory of using a workflow tool rather than building a pipeline from scratch.

2 Likes

Wow! Okay yes I was scratching my head here thinking - everything you did looks correct to me, haha. definately noted and happy building!

2 Likes

I am familiar with API auth, but I appreciate the input and help. It allowed me to do some additional digging :slight_smile:

1 Like

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