ComfyUI Node

decode

Turn b'...' back into readable text

By StableLlama·Created about a year ago·Updated 4 days ago· 48
decode
    • STRING
    bytes_stringb''
    encoding
    errors

    Every now and then your text shows up looking like b'\xc3\xb6\xc3\xa4' - a bytes literal written out as a string. That's exactly what this pack's encode node produces, and decode is the round-trip that turns it back into readable text. They're designed to be used as a pair.

    What it does

    Here's the honest framing: ComfyUI moves strings around, not real bytes objects. So this node doesn't decode actual bytes - it parses the string representation of bytes. Give it bytes_string in the b'...' form, and it strips the b prefix and quotes, resolves the escape sequences, and decodes the result using your chosen encoding.

    The inputs that matter:

    • bytes_string - the bytes-literal string, default b'' (required).
    • encoding - dropdown: utf-8 (default), ascii, latin-1, utf-16, utf-32, cp1252 (required).
    • errors - dropdown: strict (default), ignore, replace, backslashreplace (required).

    Output: one STRING.

    The error-handling twist

    This node doesn't throw. If the input isn't in b'...' form, you get back a string like "Input is not a bytes string representation: ...". If decoding fails, you get "Decoding error: ...". That's friendly - nothing crashes - but it's also a trap: those error strings flow downstream as if they were real output. If you're chaining into a prompt or a filename, a failed decode silently becomes part of the text.

    Why you'd reach for it

    Mostly as the partner to encode. The realistic use is text that arrived escaped - from a file you read, an API response, or another node that produced a bytes-literal representation - and you want the human-readable version back. Keep the encoding consistent between encode and decode, or the round-trip will produce garbage (that's usually the first thing people check when output looks wrong).

    Installing

    Part of Basic data handling by StableLlama. In ComfyUI Manager search "Basic data handling" → Install → restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    Restart. The pack has zero runtime dependencies - pure stdlib - so this is one of the rare node installs that can't break anything else.

    Where people get burned

    The biggest misconception is expecting real bytes in and real text out. The input must literally start with b' or b" for the node to treat it as a bytes literal; anything else returns the "not a bytes string representation" message. And remember the escape handling is a simplified implementation - very exotic escape sequences may not survive the trip, so test your round-trip before relying on it.

    CategoryBasic/STRING

    Inputs (3)

    NameTypeDefaultDescription
    bytes_stringSTRINGb''
    encodingCOMBO6 options: utf-8, ascii, latin-1, utf-16, utf-32, cp1252
    errorsCOMBO4 options: strict, ignore, replace, backslashreplace

    Outputs (1)

    NameTypeDescription
    STRINGSTRING