Nodes/ComfyUI_SaveImageWithMetaDataUniversal/Save generated_user_rules.py
ComfyUI Node

Save generated_user_rules.py

Write your hand-edited capture rules back without touching a text editor

By xxmjskxx·Created about a year ago·Updated about a month ago· 25
Save generated_user_rules.py
    • status
    rules_text
    appendtrue

    SaveCustomMetadataRules is the safe path: it takes the scanner's JSON and merges it into your rules with backups and version stamps. But sometimes you don't want the safe path. Sometimes you've got Show generated_user_rules.py output on screen, you've spotted a rule that maps the wrong input, and you just want to fix the text and go. Save generated_user_rules.py is the escape hatch for that: it takes an arbitrary text blob, validates it as Python, and writes it back to generated_user_rules.py.

    Think of it as the "edit the config file from inside ComfyUI" node. It exists because the author's own workflow - and the README's troubleshooting section - explicitly recommends hand-adjusting the generated rules when the scanner's heuristics guess wrong for a weird node.

    The inputs

    • rules_text - the full rules module text to write. There's no magic here: it's a STRING, so whatever you wire in (or paste) becomes the file. The intended source is the generated_user_rules.py output from Show generated_user_rules.py - wire that node into this one, tweak the text, run.
    • append (default True) - if True, the incoming text is appended to the existing file; if False, it overwrites the file entirely.

    The status string output tells you whether the write succeeded - and because the node validates the syntax before writing, a broken edit fails cleanly instead of nuking your rules file with a SyntaxError at next load.

    The workflow it enables

    1. Run Show generated_user_rules.py, wire its output into this node's rules_text.
    2. Edit the text however you like - a SaveImage-style widget won't cut it, so this is where a text editor or an intermediate text-manipulation node earns its keep.
    3. Run, read status, restart isn't needed - the rules load fresh at next save.

    Two warnings worth taking seriously

    First, append defaults to True, which is safe-ish - you're adding to whatever's there. But the moment you flip to overwrite, you're replacing the entire generated module. If you're going down this path, you should have your Save Custom Metadata Rules backups intact, because this node has no backup mechanism of its own.

    Second, this writes a Python module that the loader imports. The pack skips modules named like *_examples when loading, but this file is the real one - a hand-edit that breaks the schema (wrong structure, renamed a metafield constant, mangled syntax) will fail validation on write, but a structurally-valid-but-semantically-wrong rules file will load and just not capture what you expect. That's why the companion Show generated_user_rules.py view loop exists: look before you save, save, then re-view to confirm.

    For most people, SaveCustomMetadataRules is the right tool and this one is the power tool. Keep append on, keep a backup, and it'll get you out of any rule-shaped hole the scanner digs for you.

    CategorySaveImageWithMetaDataUniversal/rules

    Inputs (2)

    NameTypeDefaultDescription
    rules_textSTRING
    appendBOOLEANtrueIf true, append new rules to existing file; if false, overwrite existing file.

    Outputs (1)

    NameTypeDescription
    statusSTRING