{
  "name": "🧩#121 - AI Document Quality Review",
  "nodes": [
    {
      "parameters": {},
      "id": "12100000-0000-4000-8000-000000000001",
      "name": "When clicking 'Execute workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Draft document to evaluate\nreturn [{\n  json: {\n    draftTitle: \"Website Proposal Draft\",\n    draftText: `Hi,\n \nWe can build you a website. It will look nice and help your business grow.\nThe project includes design and development and some SEO stuff.\nIt should take a few weeks and cost around £2000.\n \nLet me know if you want to start.\n \nThanks`\n  }\n}];"
      },
      "id": "12100000-0000-4000-8000-000000000002",
      "name": "Draft",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        224,
        0
      ]
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "messages": {
          "values": [
            {
              "content": "You are an expert document quality reviewer for a professional agency, not a writer. Your task is to critically analyze the provided draft (proposal, email, or document). Evaluate its structure, clarity, specificity, professionalism, and actionability before suggesting any fixes.\n\nScore the document across criteria and return a valid JSON object using EXACTLY this schema:\n{\n  \"overallScore\": \"35/10\",\n  \"scores\": {\n    \"clarity\": \"45/10\",\n    \"structure\": \"30/10\",\n    \"specificity\": \"25/10\",\n    \"professionalism\": \"55/10\",\n    \"actionability\": \"30/10\"\n  },\n  \"weakSections\": [\n    {\n      \"section\": string,       // e.g. \"Scope and deliverables\"\n      \"problem\": string,       // root problem with quote e.g. \\\"design and development and some SEO stuff\\\" is vague...\n      \"fix\": string           // concrete actionable advice on what to write\n    }\n  ]\n}\nRules:\n- Be critical, objective, and thorough.\n- Point out missing information (deliverables, timelines, payment terms, calls to action).\n- Respond ONLY with valid JSON (no markdown formatting, no commentary).",
              "role": "system"
            },
            {
              "content": "=Document Draft to Review:\n\nTitle: {{ $json.draftTitle }}\n\nText:\n{{ $json.draftText }}"
            }
          ]
        },
        "jsonOutput": true,
        "options": {}
      },
      "id": "12100000-0000-4000-8000-000000000003",
      "name": "Message a model",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        448,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Parse AI Reviewer JSON (handles raw object or string/fenced output)\nconst c = $json.text ?? $json.message?.content ?? $json.content ?? $json;\nlet d;\nif (c && typeof c === \"object\") {\n  d = c;\n} else {\n  let txt = (c ?? \"\").toString().trim();\n  const fence = txt.match(/```(?:json)?\\s*([\\s\\S]*?)```/i);\n  if (fence) txt = fence[1].trim();\n  const s = txt.indexOf(\"{\"), e = txt.lastIndexOf(\"}\");\n  if (s !== -1 && e !== -1) txt = txt.slice(s, e + 1);\n  try {\n    d = JSON.parse(txt);\n  } catch (err) {\n    return [{ json: { message: \"⚠️ Could not parse the document quality review as JSON.\\n\\n\" + (c ?? \"\") } }];\n  }\n}\n\n// Format criteria scores\nconst fmtScore = val => {\n  if (val === undefined || val === null) return \"N/A\";\n  return String(val);\n};\n\nlet scoresList = \"\";\nif (d.scores && typeof d.scores === \"object\") {\n  scoresList = Object.entries(d.scores)\n    .map(([k, v]) => `• ${k}: ${fmtScore(v)}`)\n    .join(\"\\n\");\n}\n\n// Format weak sections\nlet weakSectionsText = \"\";\nif (Array.isArray(d.weakSections)) {\n  weakSectionsText = d.weakSections.map((w, idx) => {\n    const title = w.section || w.title || `Section ${idx + 1}`;\n    return `${idx + 1}. ${title}\\nProblem: ${w.problem || \"\"}\\nFix: ${w.fix || \"\"}`;\n  }).join(\"\\n\\n\");\n}\n\nconst message =\n`📑 AI Document Quality Review\\n\\nOverall Score: ${fmtScore(d.overallScore)}\\n\\nScores:\\n${scoresList}\\n\\nWeak Sections:\\n${weakSectionsText}`;\n\nreturn [{\n  json: {\n    message,\n    review: d\n  }\n}];"
      },
      "id": "12100000-0000-4000-8000-000000000004",
      "name": "Parse Agent Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        800,
        0
      ]
    },
    {
      "parameters": {
        "chatId": "YOUR_TELEGRAM_CHAT_ID",
        "text": "={{ $json.message }}",
        "additionalFields": {}
      },
      "id": "12100000-0000-4000-8000-000000000005",
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1024,
        0
      ]
    }
  ],
  "connections": {
    "When clicking 'Execute workflow'": {
      "main": [
        [
          {
            "node": "Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Draft": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message a model": {
      "main": [
        [
          {
            "node": "Parse Agent Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Agent Response": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {
    "When clicking 'Execute workflow'": [
      {
        "json": {},
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "Draft": [
      {
        "json": {
          "draftTitle": "Website Proposal Draft",
          "draftText": "Hi,\n \nWe can build you a website. It will look nice and help your business grow.\nThe project includes design and development and some SEO stuff.\nIt should take a few weeks and cost around £2000.\n \nLet me know if you want to start.\n \nThanks"
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "Message a model": [
      {
        "json": {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": {
              "overallScore": "35/10",
              "scores": {
                "clarity": "45/10",
                "structure": "30/10",
                "specificity": "25/10",
                "professionalism": "55/10",
                "actionability": "30/10"
              },
              "weakSections": [
                {
                  "section": "Scope and deliverables",
                  "problem": "\"design and development and some SEO stuff\" is vague and doesn't define what is included (pages, features, SEO deliverables, copywriting, analytics, content, etc.).",
                  "fix": "List concrete deliverables (e.g., number of pages, CMS or static site, design revisions, SEO items like technical audit, on-page optimization, keyword research, meta tags, schema, local SEO, analytics setup) and explicitly state what is excluded."
                },
                {
                  "section": "Timeline",
                  "problem": "\"a few weeks\" is not a specific commitment and doesn't account for dependencies (content availability, approvals).",
                  "fix": "Provide a timeline range with milestones (discovery, design, development, QA, launch) and conditions (e.g., client provides content by a certain date)."
                },
                {
                  "section": "Pricing",
                  "problem": "\"around £2000\" lacks transparency about what the price covers, whether it's fixed/estimated, and whether there are additional charges.",
                  "fix": "State whether pricing is fixed or estimate, what's included in the £2000, payment terms (deposit, installments), and provide a contingency/extra options pricing."
                },
                {
                  "section": "Next steps",
                  "problem": "\"Let me know if you want to start\" doesn't specify what the recipient should do next or what information is needed.",
                  "fix": "Include a clear call to action: schedule a call, request key details (business type, goals, existing assets, preferred pages), and outline how approval and contract signing will work."
                }
              ]
            }
          }
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "Parse Agent Response": [
      {
        "json": {
          "message": "📑 AI Document Quality Review\n\nOverall Score: 35/10\n\nScores:\n• clarity: 45/10\n• structure: 30/10\n• specificity: 25/10\n• professionalism: 55/10\n• actionability: 30/10\n\nWeak Sections:\n1. Scope and deliverables\nProblem: \"design and development and some SEO stuff\" is vague and doesn't define what is included (pages, features, SEO deliverables, copywriting, analytics, content, etc.).\nFix: List concrete deliverables (e.g., number of pages, CMS or static site, design revisions, SEO items like technical audit, on-page optimization, keyword research, meta tags, schema, local SEO, analytics setup) and explicitly state what is excluded.\n\n2. Timeline\nProblem: \"a few weeks\" is not a specific commitment and doesn't account for dependencies (content availability, approvals).\nFix: Provide a timeline range with milestones (discovery, design, development, QA, launch) and conditions (e.g., client provides content by a certain date).\n\n3. Pricing\nProblem: \"around £2000\" lacks transparency about what the price covers, whether it's fixed/estimated, and whether there are additional charges.\nFix: State whether pricing is fixed or estimate, what's included in the £2000, payment terms (deposit, installments), and provide a contingency/extra options pricing.\n\n4. Next steps\nProblem: \"Let me know if you want to start\" doesn't specify what the recipient should do next or what information is needed.\nFix: Include a clear call to action: schedule a call, request key details (business type, goals, existing assets, preferred pages), and outline how approval and contract signing will work.",
          "review": {
            "overallScore": "35/10",
            "scores": {
              "clarity": "45/10",
              "structure": "30/10",
              "specificity": "25/10",
              "professionalism": "55/10",
              "actionability": "30/10"
            },
            "weakSections": [
              {
                "section": "Scope and deliverables",
                "problem": "\"design and development and some SEO stuff\" is vague and doesn't define what is included (pages, features, SEO deliverables, copywriting, analytics, content, etc.).",
                "fix": "List concrete deliverables (e.g., number of pages, CMS or static site, design revisions, SEO items like technical audit, on-page optimization, keyword research, meta tags, schema, local SEO, analytics setup) and explicitly state what is excluded."
              },
              {
                "section": "Timeline",
                "problem": "\"a few weeks\" is not a specific commitment and doesn't account for dependencies (content availability, approvals).",
                "fix": "Provide a timeline range with milestones (discovery, design, development, QA, launch) and conditions (e.g., client provides content by a certain date)."
              },
              {
                "section": "Pricing",
                "problem": "\"around £2000\" lacks transparency about what the price covers, whether it's fixed/estimated, and whether there are additional charges.",
                "fix": "State whether pricing is fixed or estimate, what's included in the £2000, payment terms (deposit, installments), and provide a contingency/extra options pricing."
              },
              {
                "section": "Next steps",
                "problem": "\"Let me know if you want to start\" doesn't specify what the recipient should do next or what information is needed.",
                "fix": "Include a clear call to action: schedule a call, request key details (business type, goals, existing assets, preferred pages), and outline how approval and contract signing will work."
              }
            ]
          }
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "Telegram": [
      {
        "json": {
          "ok": true,
          "result": {
            "message_id": 121,
            "chat": {
              "id": 6811413428,
              "type": "private"
            },
            "date": 1789718400,
            "text": "📑 AI Document Quality Review\n\nOverall Score: 35/10\n\nScores:\n• clarity: 45/10\n• structure: 30/10\n• specificity: 25/10\n• professionalism: 55/10\n• actionability: 30/10\n\nWeak Sections:\n1. Scope and deliverables\nProblem: \"design and development and some SEO stuff\" is vague and doesn't define what is included (pages, features, SEO deliverables, copywriting, analytics, content, etc.).\nFix: List concrete deliverables (e.g., number of pages, CMS or static site, design revisions, SEO items like technical audit, on-page optimization, keyword research, meta tags, schema, local SEO, analytics setup) and explicitly state what is excluded.\n\n2. Timeline\nProblem: \"a few weeks\" is not a specific commitment and doesn't account for dependencies (content availability, approvals).\nFix: Provide a timeline range with milestones (discovery, design, development, QA, launch) and conditions (e.g., client provides content by a certain date).\n\n3. Pricing\nProblem: \"around £2000\" lacks transparency about what the price covers, whether it's fixed/estimated, and whether there are additional charges.\nFix: State whether pricing is fixed or estimate, what's included in the £2000, payment terms (deposit, installments), and provide a contingency/extra options pricing.\n\n4. Next steps\nProblem: \"Let me know if you want to start\" doesn't specify what the recipient should do next or what information is needed.\nFix: Include a clear call to action: schedule a call, request key details (business type, goals, existing assets, preferred pages), and outline how approval and contract signing will work."
          }
        },
        "pairedItem": {
          "item": 0
        }
      }
    ]
  }
}
