[KongchangAI]
· 3 min read· 1,533 words

Building a SOC Triage Agent with n8n: AI Recommendations, Rule-Based Approval

Building a SOC Triage Agent with n8n: AI Recommendations, Rule-Based Approval

A developer built a SOC alert triage agent in n8n where AI only recommends and code decides approval, with an open-source demo.

The article introduces an open-source security alert triage workflow built on n8n, centered on the principle "AI proposes, rules decide": a Gemini Agent enriches events, queries threat intelligence, and suggests actions, while approval for sensitive operations like host isolation and credential reset is determined by an independent code step rather than prompts. The flow covers four simulated event types, with results validated and pushed to Slack for approval and stored in Postgres, all on free tiers. The author shares three lessons and positions the project as a demo prototype with mocked threat intel, no approval callback, and no automatic execution.

Security Operations Centers (SOCs) face a flood of alerts every day, most of which are noise. One developer built a triage agent with n8n that lets AI perform the first round of investigation like a junior analyst, but draws a clear boundary: AI only makes recommendations, and whether sensitive actions are triggered is decided by hardcoded code rules. The project is open-sourced on GitHub and is collecting community feedback.

Overall Design: Let AI Investigate, Let Rules Adjudicate

The core idea of this workflow can be summed up in one sentence—AI proposes, rules decide. The agent checks source IPs, assesses severity, and suggests actions, but for sensitive operations like "isolate host" or "reset credentials," the model is never allowed to decide on its own.

According to the author's explanation in a Reddit post, this split exists because the model may offer seemingly reasonable suggestions, but it cannot bear responsibility for the consequences. Putting approval logic in code makes auditing easier and closes off the possibility of the model bypassing restrictions through wording. Interestingly, the approval rules are not written in the prompt but exist as an independent code step—something especially critical for compliance scenarios.

Workflow Breakdown: The Full Chain from Event to Approval

The entire flow starts with simulated security events, covering four typical scenarios: SSH brute force, process beaconing (outbound C2), impossible travel login for an admin account, and internal scanning.

Event Enrichment and AI Investigation

Each event first goes through an enrichment step that supplements the host's criticality level (low, medium, high, critical) from a lookup table in code. The AI Agent (using Gemini) then calls the threat_intel_lookup tool, passing in the source IP, which returns a JSON payload with severity, verdict, recommended action, and a one-line summary.

The design intent here is clear: host criticality comes from a code lookup and is deterministic data; the threat intelligence query is initiated by the model, but its result structure is fixed, making downstream validation easier.

Threat Intelligence Lookup and Structured Return

threat_intel_lookup is a tool invoked by the AI Agent (Function Calling / Tool Use). It takes an IP address as input and returns a fixed JSON structure. LLMs do not inherently possess real-time knowledge of IP reputation; the purpose of tool calling is to bring external deterministic data sources into the reasoning chain: the model decides "whether to look up and what to look up," while the lookup results are provided by an external service. Because the return structure is fixed (four fields: severity, verdict, recommended action, and summary), downstream code steps can validate against stable field names rather than parsing free text. In real systems, this tool would typically connect to threat intelligence platforms such as VirusTotal, AbuseIPDB, or GreyNoise, or to an organization's internal asset and intelligence databases; mock data is used here to make the demo reproducible and independent of API quotas.

Code Implementation of Approval Rules

The AI's return result goes through a code step for validation. The rules themselves are fairly straightforward—isolate_host, reset_credentials, and any high/critical severity event on a high or critical criticality host are all flagged as needs_approval.

Requests meeting the conditions are pushed to a Slack approval message via an IF node, while all records are written to Postgres. The author emphasizes that even if the model recommends isolating a host, the code still independently determines whether human intervention is needed—the model has no room to bypass it.

Why Put Approval Logic in Code Rather Than in the Prompt

Prompt constraints are "soft constraints": the model may deviate from instructions due to wording changes, context length, temperature parameters, or adversarial input, and such deviations are difficult to detect systematically. Code rules, by contrast, execute deterministically—the same input always yields the same judgment, can be unit-tested, version-diffed, and traced line by line during audits. For destructive and irreversible operations like "isolate host" or "reset credentials," compliance frameworks (such as the change and access control requirements in SOC 2 and ISO 27001) typically require an explicit human authorization step. Isolating the decision logic into a separate code step also brings an engineering benefit: rules are decoupled from the model, so approval behavior stays unchanged when swapping models or modifying prompts, and rule adjustments do not require re-tuning prompts. The needs_approval flag mentioned in the article is precisely a product of this decoupling—it is a structured field, not a natural-language description.

Tech Stack and Cost

The entire solution runs on n8n Cloud, Gemini, Slack, and Supabase (Postgres), all using free tiers. For security teams looking to validate ideas at low cost, this combination has a low barrier to entry.

On n8n and Low-Code Orchestration

n8n is an open-source workflow automation tool. Its node-based canvas strings HTTP requests, conditional branches, code snippets, and database writes into a visual pipeline, positioning itself between SaaS automation tools like Zapier and hand-rolled scripts. Its key feature is the ability to embed JavaScript/Python code nodes in the flow—this is exactly what makes "rules decide" possible in this article: model calls and deterministic judgments can coexist in the same chain. The self-hosted version is free, while the Cloud version is billed by execution count; combined with Gemini's free tier and Supabase's free tier, the prototype stage is nearly zero-cost. Note that the convenience of low-code platforms also means weaker observability and error handling than dedicated backend services. When moving to production, key decision logic usually needs to be migrated out to independent services, with the workflow only handling orchestration.

Three Lessons Learned

The author summarized three practical lessons in the post, offering direct reference value for readers preparing to get started with n8n:

  • Put approval rules in code, not in prompts—the auditability is completely different;
  • Validate AI output before it reaches Slack to prevent malformed or over-privileged suggestions from flowing into the human review step;
  • Slack message text must use Expression mode, otherwise {{ }} will be displayed literally as plain text.

The third point seems trivial, but it is a pitfall that n8n users easily fall into repeatedly.

The Difference Between Expression Mode and Fixed Text in n8n

Text fields in n8n have two modes: Fixed text and Expression. Only when switched to Expression mode is the field content evaluated as a template, and placeholders like {{ $json.field }} replaced with actual data from upstream nodes; in Fixed text mode, double curly braces are output literally as ordinary characters. This differs from the default behavior of many template engines, making it a high-frequency pitfall for newcomers. Similar implicit behaviors include: data passing between nodes is in units of item arrays, field names are case-sensitive, and expression evaluation happens at node execution time rather than edit time—what you see during debugging is a snapshot of the last run. Understanding these mechanisms can significantly reduce issues like "the flow runs but the message content is wrong."

Limitations: This Is a Demo Prototype

The author proactively draws the boundaries: the threat intelligence tool is a mock with hardcoded data, the demo runs on simulated events, and approval is only presented as a Slack message. There is currently no callback on the Slack side, so no action is executed automatically.

In other words, the value of this project lies in demonstrating the architectural pattern of "AI recommendations + rule-based approval," not in being a production-ready system. Real deployment would still require wiring up approval callbacks, connecting to real threat intelligence sources, and handling practical issues such as false positives and alert fatigue.

What Other Signals Can Approval Rules Include?

The author ends with an open question: besides host criticality and severity, what other signals should approval rules incorporate?

From a security engineering perspective, directions worth considering include asset ownership (whether production environments or core data are involved), repetition frequency within an event time window, historical false positive rates, and action reversibility. Together these signals determine the risk weight of an action, rather than relying solely on the model's severity judgment.

Perhaps the most valuable takeaway from this project is not the specific implementation, but that sense of boundaries—drawing the red line between automation and human control with code rather than prompts.

One-line Summary

A developer built a SOC alert triage agent with n8n where AI only recommends and code determines approval, with an open-source demo.

Paragraph Summary

The article introduces an open-source security alert triage workflow based on n8n, whose core design principle is "AI proposes, rules decide": a Gemini Agent enriches events, queries threat intelligence, and suggests actions, while approval decisions for sensitive operations like host isolation and credential reset are made by an independent code step rather than written in prompts. The flow covers four types of simulated events—SSH brute force, beaconing, impossible travel login, and internal scanning—with results validated, pushed to Slack for approval, and stored in Postgres, all on free-tier services. The author summarizes three lessons: rules in code improve auditability, AI output should be validated before reaching Slack, and Slack messages require Expression mode. The project is positioned as a demo prototype with mocked threat intelligence, no approval callback, and no automatic action execution, and it raises an open question about what other signals approval rules should incorporate.

#n8n#SOC triage#security automation#AI agent#Gemini#threat intelligence#workflow automation
Share:

Related articles