n8n - ✅(Solved) Fix Bug: Guardrails node threshold hint contradicts actual node behavior [2 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
n8n-io/n8n#29015Fetched 2026-04-24 06:12:41
View on GitHub
Comments
3
Participants
3
Timeline
7
Reactions
0
Author
Timeline (top)
commented ×3cross-referenced ×1labeled ×1mentioned ×1

Error Message

Describe the problem/error/question

What is the error message (if any)?

No runtime error. This is a UI documentation bug — misleading hint text in the node's Threshold field description.

  • error: all

Fix Action

Fixed

PR fix notes

PR #29018: fix(guardrails): align threshold hint with behavior

Description (problem / solution / changelog)

Summary

  • fix the Guardrails threshold hint so it matches the existing trigger logic
  • add a focused test covering the threshold hint text in the node description

Root cause

The Threshold field hint said inputs scoring less than the threshold would be treated as violations, but the Guardrails trigger logic actually fires when an input is flagged and its confidence is at or above the threshold.

Changes

  • update the Threshold hint copy in nodes/Guardrails/description.ts
  • add nodes/Guardrails/test/description.test.ts to lock the wording to the current behavior

Validation

  • pnpm --dir packages/@n8n/nodes-langchain exec jest nodes/Guardrails/test/description.test.ts --runInBand
  • pnpm --dir packages/@n8n/nodes-langchain exec eslint nodes/Guardrails/description.ts nodes/Guardrails/test/description.test.ts
  • git diff --check

Closes #29015

Changed files

  • packages/@n8n/nodes-langchain/nodes/Guardrails/description.ts (modified, +1/-2)
  • packages/@n8n/nodes-langchain/nodes/Guardrails/test/description.test.ts (added, +27/-0)

Code Example

const triggered = result.flagged && result.confidenceScore >= threshold;

---

// Before
hint: 'Inputs scoring less than this will be treated as violations',

// After (Option A — minimal, aligned with code):
hint: 'Inputs scoring at or above this threshold (when flagged) will be treated as violations',

// After (Option B — shorter, aligned with tooltip wording):
hint: 'Flagged inputs with confidence at or above this threshold will be treated as violations',

---

{
  "nodes": [
    {
      "parameters": {
        "text": "={{ $('Code Node — Input Sanitization1').item.json.emailBody }}{{JSON.stringify($json.attachmentRows) }}",
        "guardrails": {
          "jailbreak": {
            "value": {
              "threshold": 0.7
            }
          }
        },
        "customizeSystemMessage": true
      },
      "id": "766c5336-3141-40d6-a5fd-0d41390fb1d6",
      "name": "Guardrails — Input1",
      "type": "@n8n/n8n-nodes-langchain.guardrails",
      "typeVersion": 2,
      "position": [
        3984,
        2784
      ],
      "onError": "continueErrorOutput"
    }
  ],
  "connections": {
    "Guardrails — Input1": {
      "main": [
        [],
        []
      ]
    }
  },
  "pinData": {},
  "meta": {
    "instanceId": "70f8809962a15cc6cf75168d0d844c7c78da7a81cc99b5ae5fe6741c395b0cbd"
  }
}

---

[
  {
    "response": {
      "generations": [
        [
          {
            "text": "

---

With this output (`confidenceScore: 0.0, flagged: false`) and threshold = `0.7`, the code at `model.ts:105` computes:
RAW_BUFFERClick to expand / collapse

Describe the problem/error/question

The hint text below the Threshold field in the Guardrails node contradicts the actual violation logic implemented in packages/@n8n/nodes-langchain/nodes/Guardrails/helpers/model.ts.

Current hint in UI:

Inputs scoring less than this will be treated as violations

Actual logic (helpers/model.ts line 105):

const triggered = result.flagged && result.confidenceScore >= threshold;

A violation is triggered when flagged === true AND confidenceScore >= threshold — i.e., inputs scoring at or above threshold are violations, not less than.

The tooltip on the ? icon ("Minimum confidence threshold to trigger the guardrail") is correct. Only the hint text below the input contradicts both the tooltip and the code.

Impact: users configuring the threshold read the hint literally and reason about the behavior backwards (e.g., "if I set 0.9, everything scoring below 0.9 will be blocked"). That breaks intuition for both tuning false-positive/false-negative tradeoffs and debugging why a guardrail is or isn't firing.

Suggested fix — one-line change in packages/@n8n/nodes-langchain/nodes/Guardrails/description.ts:

// Before
hint: 'Inputs scoring less than this will be treated as violations',

// After (Option A — minimal, aligned with code):
hint: 'Inputs scoring at or above this threshold (when flagged) will be treated as violations',

// After (Option B — shorter, aligned with tooltip wording):
hint: 'Flagged inputs with confidence at or above this threshold will be treated as violations',

What is the error message (if any)?

No runtime error. This is a UI documentation bug — misleading hint text in the node's Threshold field description.

Please share your workflow/screenshots/recording

{
  "nodes": [
    {
      "parameters": {
        "text": "={{ $('Code Node — Input Sanitization1').item.json.emailBody }}{{JSON.stringify($json.attachmentRows) }}",
        "guardrails": {
          "jailbreak": {
            "value": {
              "threshold": 0.7
            }
          }
        },
        "customizeSystemMessage": true
      },
      "id": "766c5336-3141-40d6-a5fd-0d41390fb1d6",
      "name": "Guardrails — Input1",
      "type": "@n8n/n8n-nodes-langchain.guardrails",
      "typeVersion": 2,
      "position": [
        3984,
        2784
      ],
      "onError": "continueErrorOutput"
    }
  ],
  "connections": {
    "Guardrails — Input1": {
      "main": [
        [],
        []
      ]
    }
  },
  "pinData": {},
  "meta": {
    "instanceId": "70f8809962a15cc6cf75168d0d844c7c78da7a81cc99b5ae5fe6741c395b0cbd"
  }
}

Reproduction steps:

  1. Paste the above single-node workflow (any Guardrails node variant works — Jailbreak shown here).
  2. Open the node configuration panel.
  3. Locate the Threshold field.
  4. Observe the hint text below the input box:

    Inputs scoring less than this will be treated as violations

  5. Compare with the tooltip on the ? icon next to the label:

    Minimum confidence threshold to trigger the guardrail (0.0 to 1.0)

  6. Inspect the source code of the node at packages/@n8n/nodes-langchain/nodes/Guardrails/helpers/model.ts line 105 to confirm the actual logic: triggered = flagged && confidenceScore >= threshold.

Share the output returned by the last node

Example output from the Guardrails node showing the confidenceScore and flagged fields that the threshold comparison operates on (clean input, model classifies as safe):

[
  {
    "response": {
      "generations": [
        [
          {
            "text": "```json\n{\"confidenceScore\":0.0,\"flagged\":false}\n```"
          }
        ]
      ]
    },
    "tokenUsageEstimate": {
      "completionTokens": 17,
      "promptTokens": 1071,
      "totalTokens": 1088
    }
  }
]

With this output (confidenceScore: 0.0, flagged: false) and threshold = 0.7, the code at model.ts:105 computes:

triggered = false && (0.0 >= 0.7)
triggered = false

→ safe branch. Correct behavior — clean input passes. But the hint text incorrectly claims "scoring less than 0.7 = violation", which would wrongly suggest the input should be blocked.

Debug info

core

  • n8nVersion: 2.13.3
  • platform: docker (cloud)
  • nodeJsVersion: 24.13.1
  • nodeEnv: production
  • database: sqlite
  • executionMode: regular
  • concurrency: 5
  • license: enterprise (sandbox)

storage

  • success: all
  • error: all
  • progress: false
  • manual: true
  • binaryMode: filesystem

pruning

  • enabled: true
  • maxAge: 168 hours
  • maxCount: 2500 executions

client

  • userAgent: mozilla/5.0 (macintosh; intel mac os x 10_15_7) applewebkit/605.1.15 (khtml, like gecko) version/18.6 safari/605.1.15
  • isTouchDevice: false

Generated at: 2026-04-23T19:06:26.994Z


Additional context

Happy to open a PR if maintainers prefer contribution over fix-by-maintainer.

extent analysis

TL;DR

Update the hint text in packages/@n8n/nodes-langchain/nodes/Guardrails/description.ts to reflect the correct logic that inputs scoring at or above the threshold are treated as violations.

Guidance

  • Review the current hint text and compare it with the actual logic implemented in helpers/model.ts to understand the discrepancy.
  • Update the hint text to one of the suggested options: 'Inputs scoring at or above this threshold (when flagged) will be treated as violations' or 'Flagged inputs with confidence at or above this threshold will be treated as violations'.
  • Verify the change by checking the hint text in the UI and ensuring it aligns with the tooltip and the actual logic.
  • Test the Guardrails node with different threshold values to confirm the correct behavior.

Example

The corrected hint text could be:

hint: 'Inputs scoring at or above this threshold (when flagged) will be treated as violations',

or

hint: 'Flagged inputs with confidence at or above this threshold will be treated as violations',

Notes

This fix only addresses the UI documentation bug and does not affect the actual logic or behavior of the Guardrails node.

Recommendation

Apply the workaround by updating the hint text in description.ts to reflect the correct logic, as this is a UI documentation bug that can be easily fixed without requiring a full version upgrade.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

n8n - ✅(Solved) Fix Bug: Guardrails node threshold hint contradicts actual node behavior [2 pull requests, 3 comments, 3 participants]