On this page
Sommatic Docs
Open portal

HTML Text Extraction

Extracts the main readable content from HTML or XHTML documents using trafilatura with content-boundary detection.

View as Markdown
Open in
AI Available ai.html.extract.text Version 1.0.0 Execution: async

Extracts the main readable text of an HTML document with trafilatura, dropping navigation, scripts, comments and other boilerplate; tables are kept.

Strips navigation chrome, scripts, style blocks, advertising containers, cookie banners, headers, footers, and comment threads while preserving the substantive article body.

Features:

  • Boilerplate removal: Detects and removes page chrome based on trafilatura's trained extractors, tuned for modern CMS and blog layouts.
  • Structural preservation: Retains headings, paragraphs, ordered and unordered lists, and blockquotes in document order.
  • Precision/recall tradeoff: favor_precision toggles between aggressive cleanup (default, fewer false positives) and permissive extraction (recovers content on unconventional layouts).
  • Metadata extraction: Pulls title, canonical URL, author, publish date, site name, and language when surfaced by the page's meta tags, Open Graph, or JSON-LD.
  • Inputs: Accepts raw HTML as a string, base64-encoded HTML, or a local file path.

How it works

  1. Reads content (raw HTML string), content_base64 and file_path from the node config, falling back to the upstream payload; fails on error when all three are missing.
  2. Uses the first source present in this order: content, content_base64 (decoded as UTF-8), file_path.
  3. Runs trafilatura with comments excluded, tables included, no formatting and favor_precision from the config (default true).
  4. Routes to empty when no text was extracted, otherwise to extracted.

In a workflow

The node as it appears in a workflow file (draft_nodes[]), and the envelope of a successful run.

{
  "node_id": "node-clean-page",
  "label": "Clean page",
  "operator_slug": "ai.html.extract.text",
  "operator_version": "1.0.0",
  "config": {
    "content": "{{ $json.body }}",
    "favor_precision": true,
    "execution": {
      "timeout_ms": 60000
    }
  }
}

Configuration

favor_precision boolean Optional

Trade recall for precision. Turn off if content is getting truncated.

Default: true

Its configuration shows the shared execution settings, but this node does not apply retries (retryOnFail, maxTries) yet. continueOnFail is not applied by any node.

Behaviour in the code

What the implementation does with these keys beyond what the schema says.

content, content_base64, file_path
Not declared in the config schema, but read from the node config first and then from the upstream payload. Usually you map them from the previous node with expressions.
favor_precision
Only false turns it off; any other value, including a missing key, keeps precision mode. Turn it off when real content is being cut.
execution
Only execution.timeout_ms is read (fallback 60000 ms). retryOnFail, maxTries, waitBetweenTries, continueOnFail and alwaysOutputData are ignored.

Output ports

extracted default

Main text was found.

Data
{
  "text": "Release notes\nThe new version adds export to CSV.",
  "chars": 48,
  "empty": false,
  "method": "trafilatura",
  "metadata": {
    "input_chars": 18342
  }
}
empty

trafilatura found no main content (very short pages, pages that are mostly navigation).

Data
{
  "text": "",
  "chars": 0,
  "empty": true,
  "method": "trafilatura",
  "metadata": {
    "input_chars": 412
  }
}
error

No input was given or the script failed.

Data
{
  "error": "content, content_base64, or file_path is required.",
  "stderr": ""
}

In expressions

What a later node can read from this node's output with $("HTML Text Extraction").item.json.<path> (write your node's label instead of HTML Text Extraction). Editor marks the paths the workflow editor suggests under Previous Nodes (the output contract); Worker marks the paths the worker really returns through extracted, from the output shown in Ports.

ExpressionEditorWorker
$("HTML Text Extraction").item.json.textstring= "Release notes\nThe new version adds export t…"
$("HTML Text Extraction").item.json.charsnumber= 48
$("HTML Text Extraction").item.json.emptyboolean= false
$("HTML Text Extraction").item.json.methodstring= "trafilatura"
$("HTML Text Extraction").item.json.metadataobject= {…}
$("HTML Text Extraction").item.json.metadata.input_charsnumberNot suggested by the editor= 18342—

— Worker: The worker returns it but the editor does not suggest it: write it by hand. Keys inside objects can depend on your data or configuration (for example one key per label).

Errors

Message Port Cause and fix
content, content_base64, or file_path is required. error None of the three sources was found in the config or the upstream payload.
Either content, content_base64, or file_path is required error Raised by the script when only file_path was given and the file does not exist on the host.
Python timed out after <timeout_ms>ms error The script exceeded the node timeout. Raise execution.timeout_ms or send a smaller file.
Python stdout exceeded MAX_STDOUT_BYTES (52428800 bytes) error The result (text or base64 files) is larger than the 50 MB cap. Split the input upstream.
Python runtime not available (ENOENT) error The host has no Python interpreter. A failed dependency install shows PythonRunner failed: <message> instead. Both are host problems, not workflow problems.

Input contract

content string Optional

Raw HTML string.

content_base64 string Optional
file_path string Optional

Output contract

text string Optional
chars number Optional
empty boolean Optional
method string Optional
metadata object Optional

Contracts (JSON Schema)

The definition exactly as the orchestrator declares it. All is the whole *.definition.js; compare it with the sections above to spot differences between the documentation and the schema. Use it to validate a node before you publish.

{
  "slug": "ai.html.extract.text",
  "name": "HTML Text Extraction",
  "category": "ai",
  "version": "1.0.0",
  "description": "Extracts the main readable content from HTML or XHTML documents using trafilatura with content-boundary detection.\n\n  Strips navigation chrome, scripts, style blocks, advertising containers, cookie banners, headers, footers, and comment threads while preserving the substantive article body.\n\n  **Features:**\n  - **Boilerplate removal:** Detects and removes page chrome based on trafilatura's trained extractors, tuned for modern CMS and blog layouts.\n  - **Structural preservation:** Retains headings, paragraphs, ordered and unordered lists, and blockquotes in document order.\n  - **Precision/recall tradeoff:** `favor_precision` toggles between aggressive cleanup (default, fewer false positives) and permissive extraction (recovers content on unconventional layouts).\n  - **Metadata extraction:** Pulls title, canonical URL, author, publish date, site name, and language when surfaced by the page's meta tags, Open Graph, or JSON-LD.\n  - **Inputs:** Accepts raw HTML as a string, base64-encoded HTML, or a local file path.",
  "capabilities": [
    "html",
    "xhtml",
    "markup",
    "text-extraction"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "favor_precision": {
        "type": "boolean",
        "title": "Favor Precision",
        "default": true,
        "description": "Trade recall for precision. Turn off if content is getting truncated."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "content": {
        "type": "string",
        "description": "Raw HTML string."
      },
      "content_base64": {
        "type": "string"
      },
      "file_path": {
        "type": "string"
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "text": {
        "type": "string"
      },
      "chars": {
        "type": "number"
      },
      "empty": {
        "type": "boolean"
      },
      "method": {
        "type": "string"
      },
      "metadata": {
        "type": "object"
      }
    }
  },
  "ports": [
    {
      "port_id": "extracted",
      "label": "Extracted",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "empty",
      "label": "Empty",
      "is_default": false,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "tags": [
    "ai",
    "html",
    "text",
    "markup"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}

Execution

Execution
async
Stateful
No
Retries (retryOnFail)
No
Capabilities
htmlxhtmlmarkuptext-extraction
Tags
aihtmltextmarkup

Notes and limits

  • Runs a Python script in a child process. The first run on a worker host creates a virtual environment and installs the script's pinned dependencies (it can take minutes and is not counted in the node timeout); later runs reuse it.
  • file_path must point to a file on the local disk of the orchestrator host that runs the node; it is not a URL and is not fetched from storage.
  • The script is killed after execution.timeout_ms; when that key is not set the code uses 60000 ms, not the schema default of 300000.
  • The node does not fetch URLs; give it HTML that an upstream node already downloaded.

Reviewed against the orchestrator code · 31e874b · 2026-11-26

Install agent tools

Give your coding agent the official Sommatic AI docs: skills, the docs MCP server and Markdown pages, so it never has to scrape the site.

Skills only. They do not update by themselves; run it again to refresh.

npx skills add https://docs.sommatic.ai
How agents read these docs