# Summarize Text

> Multi-format text summarization powered by LLM.

Source: https://docs.sommatic.ai/en/nodes/ai.summarize/

- Slug: `ai.summarize`
- Family: AI
- Version: 1.0.0
- Status: Available
- Execution: async

Multi-format text summarization powered by LLM.

This operator condenses input text into a summary using one of several modes.

**Operations**
- **Executive:** 2-3 sentence high-level summary for decision-makers.
- **Bullets:** Key points as a bullet-point list.
- **Abstractive:** Condensed rewrite preserving core meaning.
- **Extractive:** Selects the most important original sentences.
- **Structured:** Produces a JSON object with overview, key_findings, action_items, and risks_concerns sections.

**Use Cases**
- Condensing meeting transcripts or reports for stakeholders.
- Generating bullet-point digests for dashboards and notifications.
- Producing structured summaries for downstream workflow processing.

## Configuration

- `llm_provider_id` (string, optional): The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter.
- `invocation_mode` (string, optional): Transport for the LLM call. `sync` blocks until the full response arrives. `stream` consumes tokens via SSE (required for long generations). Default `sync`. Default: `sync`. Allowed values: `sync`, `stream`.
- `timeout_ms` (integer, optional): Maximum time to wait for the invocation to complete (or idle timeout between chunks in stream mode). Default 30000 for sync, 600000 for stream.
- `summary_mode` (string, optional): The summarization strategy to apply. Default: `executive`. Allowed values: `executive`, `bullets`, `abstractive`, `extractive`, `structured`.
- `max_length` (number, optional): Target maximum words for the summary (optional).
- `max_bullets` (number, optional): Maximum number of bullet points (bullets mode only). Default: `5`. Shown when: summary_mode = `bullets`.
- `language` (string, optional): Output language code (e.g., "en", "es"). Default: `en`.
- `focus_areas` (array<string>, optional): Topics or themes to prioritize in the summary (optional).

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

## Output ports

- `success` (default): Summarized
- `error`: Error

## Input contract

- `text` (string, required): The text content to summarize.
- `title` (string, optional): Optional title or heading for context.
- `context` (string, optional): Optional background context to inform the summary.

## Output contract

- `summary` (string, optional): The generated summary text.
- `sections` (object, optional): Structured sections (structured mode only).
- `key_phrases` (array<string>, optional): Key phrases detected in the text (when available).
- `word_count` (number, optional): Word count of the summary.
- `compression_ratio` (number, optional): Ratio of summary words to original words (0-1).

## In expressions

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

- `$("Summarize Text").item.json.summary` (string) = `"The supplier will deliver the missing pallet…"`: The generated summary text.
- `$("Summarize Text").item.json.sections` (object) = `null`: Structured sections (structured mode only).
- `$("Summarize Text").item.json.key_phrases` (array) = `[…] (0)`: Key phrases detected in the text (when available).
- `$("Summarize Text").item.json.word_count` (number) = `18`: Word count of the summary.
- `$("Summarize Text").item.json.compression_ratio` (number) = `0.12`: Ratio of summary words to original words (0-1).
- `$("Summarize Text").item.json.raw` (null) = `null` (Not suggested by the editor)
- `$("Summarize Text").item.json.port` (string) = `"success"` (Not suggested by the editor)


## How it works

Summarizes `text` with the LLM in one of five modes (executive, bullets, abstractive, extractive, structured) and returns the summary with its word count and compression ratio.

1. Resolves the node config: expressions in config keys are evaluated against the run; the incoming item is used as-is.
2. Merges the incoming item with the resolved config (config keys win) and reads the inputs from the result.
3. Requires `text`. Builds the instruction for `summary_mode` (default `executive`; unknown modes use it), adding `max_length`, `focus_areas` and a language line when `language` is not `en`.
4. The user message is `Title: …`, `Context: …` (when present) and `Text: …`.
5. Calls the LLM through the backend with the `llm_provider_id` record. `invocation_mode: "sync"` (default) waits for the full answer; `"stream"` reads it over SSE and joins the chunks.
6. In `structured` mode parses the JSON answer into `sections`; if it is not JSON, the raw text becomes `summary` and `sections` is `null`. In other modes the answer text is the summary.
7. Counts words (split on whitespace) and computes `compression_ratio` = summary words / input words. Routes to `success`.

## In a workflow

### Node

```json
{
  "node_id": "node-summarize",
  "label": "Summarize thread",
  "operator_slug": "ai.summarize",
  "operator_version": "1.0.0",
  "config": {
    "llm_provider_id": "<llm_provider_id>",
    "summary_mode": "executive",
    "max_length": 60,
    "language": "en",
    "focus_areas": [
      "deadlines",
      "costs"
    ]
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "success",
  "data": {
    "summary": "The supplier will deliver the missing pallets on Friday. Finance must approve the extra freight cost before Thursday.",
    "sections": null,
    "key_phrases": [],
    "word_count": 18,
    "compression_ratio": 0.12,
    "raw": null,
    "port": "success"
  }
}
```

## Output ports (behaviour in the code)

### `success`

The LLM answered. The worker returns the fields at the top level, so `data` also includes `raw` and `port`.

```json
{
  "summary": "The supplier will deliver the missing pallets on Friday. Finance must approve the extra freight cost before Thursday.",
  "sections": null,
  "key_phrases": [],
  "word_count": 18,
  "compression_ratio": 0.12,
  "raw": null,
  "port": "success"
}
```

### `error`

Validation, the LLM call or parsing failed. `data` is `{ error }` (plus `response` when the backend returned a body).

```json
{
  "error": "Missing 'text'"
}
```

## Behaviour in the code

- `llm_provider_id`: Required at runtime although the schema does not mark it as required. It is the id of an LLM provider record; the backend resolves endpoint, deployment and credentials from it.
- `summary_mode`: Temperatures: `extractive` 0, `abstractive` 0.3, the rest 0.2. Only `structured` fills `sections` and `key_phrases` (copied from `key_findings`); the other modes return `sections: null` and `key_phrases: []`.
- `max_bullets`: Default 5. Also sets the number of sentences selected in `extractive` mode, although the schema shows it only for `bullets`.
- `max_length`: A prompt hint in words; the output is not truncated.
- `timeout_ms`: `timeout_ms` only takes effect in `stream` mode, as the idle time allowed between chunks (default 600000). In `sync` mode it is logged but the backend request has no timeout.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Missing 'text'` | `error` | The incoming item has no `text`. |
| `[AiSummarize] Missing 'llm_provider_id' in node config (LlmProviderModel.id, e.g. 'wf-llm-provider-*'). …` | `error` | The node has no `llm_provider_id`. Pick an LLM provider in the node config; the legacy `model_id` key is not accepted. |
| `LLM Invocation Error: <backend message>` | `error` | The backend rejected the call (unknown or inactive provider record, provider error, credentials). Check the provider record. |
| `LLM Invocation Error: empty response from backend (<reason>).` | `error` | The backend could not be reached or returned nothing in `sync` mode. |
| `RemoteApiService.stream: idle timeout after <timeout_ms>ms` | `error` | In `stream` mode no chunk arrived within `timeout_ms`. |

## Notes and limits

- Input fields are read from the incoming item (`$json`). A key with the same name in the node config, which may be an expression, takes precedence over the input.
- `timeout_ms` only takes effect in `stream` mode, as the idle time allowed between chunks (default 600000). In `sync` mode it is logged but the backend request has no timeout.
- In `stream` mode the temperature this node sets is not forwarded to the provider, and `raw` is `null`.
- The engine does not apply `execution.retryOnFail`, `maxTries`, `waitBetweenTries` or `continueOnFail` to this node. Handle failures by wiring the `error` port.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "ai.summarize",
  "name": "Summarize Text",
  "category": "ai",
  "version": "1.0.0",
  "description": "Multi-format text summarization powered by LLM.\n\nThis operator condenses input text into a summary using one of several modes.\n\n**Operations**\n- **Executive:** 2-3 sentence high-level summary for decision-makers.\n- **Bullets:** Key points as a bullet-point list.\n- **Abstractive:** Condensed rewrite preserving core meaning.\n- **Extractive:** Selects the most important original sentences.\n- **Structured:** Produces a JSON object with overview, key_findings, action_items, and risks_concerns sections.\n\n**Use Cases**\n- Condensing meeting transcripts or reports for stakeholders.\n- Generating bullet-point digests for dashboards and notifications.\n- Producing structured summaries for downstream workflow processing.",
  "capabilities": [
    "ai",
    "nlp",
    "summarization",
    "text"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "llm_provider_id": {
        "type": "string",
        "title": "LLM Provider",
        "description": "The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter.",
        "x-ui-widget": "llm-provider-picker",
        "x-llm-provider-capabilities": [
          "chat"
        ]
      },
      "invocation_mode": {
        "type": "string",
        "title": "Invocation Mode",
        "description": "Transport for the LLM call. `sync` blocks until the full response arrives. `stream` consumes tokens via SSE (required for long generations). Default `sync`.",
        "enum": [
          "sync",
          "stream"
        ],
        "default": "sync"
      },
      "timeout_ms": {
        "type": "integer",
        "title": "Timeout (ms)",
        "description": "Maximum time to wait for the invocation to complete (or idle timeout between chunks in stream mode). Default 30000 for sync, 600000 for stream.",
        "minimum": 1000
      },
      "summary_mode": {
        "type": "string",
        "title": "Summary Mode",
        "description": "The summarization strategy to apply.",
        "enum": [
          "executive",
          "bullets",
          "abstractive",
          "extractive",
          "structured"
        ],
        "default": "executive"
      },
      "max_length": {
        "type": "number",
        "title": "Max Length (words)",
        "description": "Target maximum words for the summary (optional)."
      },
      "max_bullets": {
        "type": "number",
        "title": "Max Bullets",
        "description": "Maximum number of bullet points (bullets mode only).",
        "default": 5,
        "displayOptions": {
          "show": {
            "summary_mode": [
              "bullets"
            ]
          }
        }
      },
      "language": {
        "type": "string",
        "title": "Language",
        "description": "Output language code (e.g., \"en\", \"es\").",
        "default": "en"
      },
      "focus_areas": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "title": "Focus Areas",
        "description": "Topics or themes to prioritize in the summary (optional)."
      },
      "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": {
      "text": {
        "type": "string",
        "description": "The text content to summarize."
      },
      "title": {
        "type": "string",
        "description": "Optional title or heading for context."
      },
      "context": {
        "type": "string",
        "description": "Optional background context to inform the summary."
      }
    },
    "required": [
      "text"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "summary": {
        "type": "string",
        "description": "The generated summary text."
      },
      "sections": {
        "type": "object",
        "description": "Structured sections (structured mode only)."
      },
      "key_phrases": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "description": "Key phrases detected in the text (when available)."
      },
      "word_count": {
        "type": "number",
        "description": "Word count of the summary."
      },
      "compression_ratio": {
        "type": "number",
        "description": "Ratio of summary words to original words (0-1)."
      }
    }
  },
  "ports": [
    {
      "port_id": "success",
      "label": "Summarized",
      "is_default": true
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "async",
  "tags": [
    "ai",
    "nlp",
    "summarize",
    "text"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "llm_provider_id": {
      "type": "string",
      "title": "LLM Provider",
      "description": "The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter.",
      "x-ui-widget": "llm-provider-picker",
      "x-llm-provider-capabilities": [
        "chat"
      ]
    },
    "invocation_mode": {
      "type": "string",
      "title": "Invocation Mode",
      "description": "Transport for the LLM call. `sync` blocks until the full response arrives. `stream` consumes tokens via SSE (required for long generations). Default `sync`.",
      "enum": [
        "sync",
        "stream"
      ],
      "default": "sync"
    },
    "timeout_ms": {
      "type": "integer",
      "title": "Timeout (ms)",
      "description": "Maximum time to wait for the invocation to complete (or idle timeout between chunks in stream mode). Default 30000 for sync, 600000 for stream.",
      "minimum": 1000
    },
    "summary_mode": {
      "type": "string",
      "title": "Summary Mode",
      "description": "The summarization strategy to apply.",
      "enum": [
        "executive",
        "bullets",
        "abstractive",
        "extractive",
        "structured"
      ],
      "default": "executive"
    },
    "max_length": {
      "type": "number",
      "title": "Max Length (words)",
      "description": "Target maximum words for the summary (optional)."
    },
    "max_bullets": {
      "type": "number",
      "title": "Max Bullets",
      "description": "Maximum number of bullet points (bullets mode only).",
      "default": 5,
      "displayOptions": {
        "show": {
          "summary_mode": [
            "bullets"
          ]
        }
      }
    },
    "language": {
      "type": "string",
      "title": "Language",
      "description": "Output language code (e.g., \"en\", \"es\").",
      "default": "en"
    },
    "focus_areas": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "title": "Focus Areas",
      "description": "Topics or themes to prioritize in the summary (optional)."
    },
    "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

```json
{
  "type": "object",
  "properties": {
    "text": {
      "type": "string",
      "description": "The text content to summarize."
    },
    "title": {
      "type": "string",
      "description": "Optional title or heading for context."
    },
    "context": {
      "type": "string",
      "description": "Optional background context to inform the summary."
    }
  },
  "required": [
    "text"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "summary": {
      "type": "string",
      "description": "The generated summary text."
    },
    "sections": {
      "type": "object",
      "description": "Structured sections (structured mode only)."
    },
    "key_phrases": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Key phrases detected in the text (when available)."
    },
    "word_count": {
      "type": "number",
      "description": "Word count of the summary."
    },
    "compression_ratio": {
      "type": "number",
      "description": "Ratio of summary words to original words (0-1)."
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "success",
    "label": "Summarized",
    "is_default": true
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
