Skip to content

๐Ÿค– Template #21593: Sanitize & Ingest AI LLM JSON into Postgres with DevDeskApp and Slack โ€‹

Published on n8n.ioTemplate ID: 21593

๐Ÿ”— Template on n8n.io: n8n.io/workflows/21593

Template 21593 AI LLM JSON ingestion workflow on the n8n canvas
Figure 1: The template on the n8n canvas.

๐ŸŽฏ Overview โ€‹

LLMs often wrap JSON in markdown fences (```json โ€ฆ ```), which breaks JSON.parse and SQL inserts. This template is an ingestion gateway for model output:

  1. A Code node strips the markdown fences from rawResponse.
  2. The DevDeskApp JSON Prettifier parses and formats the cleaned string. Invalid JSON stops here with a clear error.
  3. DevDeskApp UUID adds a trace ID that links the database row, logs and Slack.
  4. DevDeskApp SHA-256 fingerprints the formatted JSON for deduplication and audit.
  5. An If node sends valid records to PostgreSQL plus a Slack log, and malformed ones to a Slack alert.

Known issue in the published version (checked 4 Nov 2026)

Running the published template end to end shows three problems. Fix them after import:

  1. Sample node fails to run. Sample Raw LLM Output (With Markdown) writes the response with four backticks (````), which is a JavaScript syntax error. Change it to a normal string, for example rawResponse: "```json\n{ ... }\n```".
  2. The hash covers an empty string. SHA-256 Integrity Hasher reads {{ $json.prettified }}, but the prettifier outputs formatted, and the previous node is the UUID generator. Use {{ $('DevDeskApp: JSON Prettifier & Schema Validator').item.json.formatted }}.
  3. The Postgres branch crashes. Format Clean Database Record calls JSON.parse(prettified.prettified). Change both prettified.prettified to prettified.formatted.

With these three changes the workflow runs through to the Postgres insert and Slack log.


๐Ÿ“ธ Pipeline โ€‹

Template 21593 pipeline: ingest, strip fences, three DevDeskApp nodes, If gate, Postgres and Slack branches
Figure 2: Node order and branches in the published template.
NodeResource ยท OperationPurpose
Strip Markdown Code FencesCode nodeRemoves leading ```json and trailing ```
DevDeskApp: JSON Prettifier & Schema Validatorjson ยท prettifyParses and formats cleanedJsonString. Throws on invalid JSON.
DevDeskApp: Trace UUID Generatorcrypto ยท uuidTrace ID
DevDeskApp: SHA-256 Integrity Hashercrypto ยท hash (sha256)Fingerprint of the formatted JSON
If: Valid JSON & Clean SchemaifRoutes to Postgres or to the error alert

The DevDeskApp node does not remove markdown fences itself. That is the Code node's job, and the node then parses and formats the result.


โšก Execution sample (with the fixes above) โ€‹

Input (rawResponse from the sample node):

text
```json
{
  "customer_id": "cust_88291",
  "sentiment": "positive",
  "confidence_score": 0.94,
  "intent": "upsell_enterprise",
  "extracted_topics": ["security_compliance", "sso", "audit_logs"],
  "action_required": true
}
```

Output of Format Clean Database Record:

json
{
  "traceId": "110ae286-1a41-46ec-9142-ec2a2b8f22c5",
  "sha256Checksum": "07df809dca91e8094d9a16a331dd03b97e1aea4ce54b8166bd1a15fa446d9d59",
  "model": "gpt-4o",
  "parsedData": {
    "customer_id": "cust_88291",
    "sentiment": "positive",
    "confidence_score": 0.94,
    "intent": "upsell_enterprise",
    "extracted_topics": ["security_compliance", "sso", "audit_logs"],
    "action_required": true
  },
  "sqlInsertQuery": "INSERT INTO ai_agent_records (trace_id, model, payload, checksum) VALUES (...)"
}

Use query parameters in production

The sample builds sqlInsertQuery by string concatenation. For real data, use the Postgres node's Insert operation or query parameters instead of running that string.


๐Ÿ“ฅ Import it โ€‹

  1. Make sure n8n-nodes-devdeskapp is installed (installation guide).
  2. Open the template on n8n.io and click Use for free, or copy the workflow JSON.
  3. Paste it onto a new workflow canvas with Ctrl + V (Cmd + V on macOS).
  4. Apply the three fixes from the known-issue box above.
  5. Add your PostgreSQL and Slack credentials, create the ai_agent_records table, and click Test workflow.

Released under the MIT License.