MessagesToText
MessagesToText turns chat history into plain text
- messages
- Text
Chat history is a list of {role, content} dicts; a lot of things you'll want to do with it - save to a file, count tokens, throw into a text widget, feed a prompt template - want a single string instead. MessagesToText is the converter that does that: it takes an LLLM_MESSAGES chain and collapses it into one readable text block.
How it works
One required input, messages (LLLM_MESSAGES), one output, Text (STRING). The handler walks your messages and joins them into lines in the shape:
USER: content of the first message
ASSISTANT: content of the second
SYSTEM: content of the third
One message per line, role uppercased, colon, space, content - newline-separated into a single string. That's the whole mechanism, and honestly that's all you usually want: a transcript you can eyeball, log, or paste.
Typical placements:
- After a completion node, to capture the full conversation as a string you can save with a text writer node.
- Before a token counter or a string-based node from another pack that can't accept
LLLM_MESSAGES. - As a human-readable preview - though for that,
ShowMessagesrenders on the node itself and is more convenient.
A quirk worth knowing
The source file actually contains two handler definitions for this node, and Python's rules mean the second one wins. The dead first version used a fullwidth colon (USER:) and even threw an error if your content contained it; the live version is the plain ASCII USER: content join described above. So what you actually get is the simple, predictable transcript. But here's the part that bites:
The pack's inverse node, TextToMessages, expects the fullwidth colon (user:) when it parses text back into messages. MessagesToText writes an ASCII colon. So copying the output of this node and feeding it to TextToMessages will fail with "Invalid message format." The two converters don't cleanly round-trip with each other - a real wart, and knowing it saves you a confused debugging session.
Installing
Pack-level install: ComfyUI Manager → search "LiteLLM" (repo Hopping-Mad-Games/ComfyUI_LiteLLM) → Install → Restart, or git clone https://github.com/Hopping-Mad-Games/ComfyUI_LiteLLM into ComfyUI/custom_nodes and pip install -r requirements.txt. Heavy first install (litellm, boto3, sentence-transformers, a LightRAG fork), but this node itself is dependency-light and calls no APIs.
Bottom line
A genuinely thin utility - the kind you'll wire in out of muscle memory once you've built one LLM workflow. The one thing to remember is the colon mismatch with TextToMessages if you try to round-trip text back into messages. If you just need the transcript as a string, it does exactly what it says on the box.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| messages | LLLM_MESSAGES | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| Text | STRING | — |