Nodes/ComfyUI_LiteLLM/TextToMessages
ComfyUI Node

TextToMessages

TextToMessages parses text into chat messages

By Hopping-Mad-Games·Created 2 years ago·Updated 11 months ago· 7
TextToMessages
    • Messages
    text

    Sometimes you don't want to build a conversation node by node - you already have it as text. Maybe you saved a chat log to a file, maybe you're testing a prompt you wrote in a text editor, maybe you're importing someone else's transcript. TextToMessages is the node that parses that text into the pack's LLLM_MESSAGES format so you can hand it to a completion node.

    How it works

    One required input, text (STRING), one output, Messages (LLLM_MESSAGES). The handler runs a regex over the input, line by line, looking for this shape:

    user:content here
    assistant:content here
    system:content here
    

    Each matching line becomes a message with its role and content. The role matching is case-insensitive (User:, USER: all work) and gets normalized to lowercase. Empty content on a matched line is rejected with a ValueError, and if nothing matches at all you get Invalid message format.

    Where this shines: paste in a pasted chat history or a prompt template with clearly-labeled turns, and the whole thing becomes a proper message chain in one step instead of four LiteLLMMessage nodes. It's also a natural endpoint for importing conversations from other tools.

    The colon trap

    Here's the thing most people hit immediately: the delimiter is the fullwidth colon (U+FF1A), not the ASCII : on your keyboard. The parser only accepts user:, assistant:, system: - with that wide Unicode colon. So:

    • user: hello → no match → "Invalid message format"
    • user:hello → parses fine

    That's unusual enough that it'll trip you up the first time, and it's compounded by the pack's own MessagesToText, which writes ASCII colons - so its output doesn't parse cleanly back in here. If you're round-tripping, you'll need to convert the colons yourself or just keep messages in LLLM_MESSAGES form.

    Wiring it up

    The output feeds anything that takes LLLM_MESSAGES: a completion node to actually run the conversation, ShowMessages to check what got parsed, or a LiteLLMMessage chain to keep appending. A sensible pipeline:

    Text (pasted transcript) → TextToMessages → ShowMessages (verify) → LiteLLMCompletion
    

    Verify with ShowMessages before spending tokens - it's cheap insurance against a silent parse error, and there's no preview here otherwise.

    Installing

    Pack-level: ComfyUI Manager → search "LiteLLM" (repo Hopping-Mad-Games/ComfyUI_LiteLLM) → Install → Restart, or clone into ComfyUI/custom_nodes and pip install -r requirements.txt. The requirements file is heavy (litellm, boto3, sentence-transformers, a LightRAG fork) even though this node is pure string parsing - no keys, no API calls.

    Bottom line

    A genuinely useful importer with one sharp edge (that fullwidth colon) and a round-trip mismatch with its sibling MessagesToText. Learn the user: syntax and it's a clean way to turn pasted transcripts into runnable conversations. Forget the colon and you'll stare at "Invalid message format" for a while - now you know why.

    CategoryETK/LLM/LiteLLM

    Inputs (1)

    NameTypeDefaultDescription
    textSTRING

    Outputs (1)

    NameTypeDescription
    MessagesLLLM_MESSAGES