Nodes/ComfyUI-PJLatent/PJ-JSON提示词提取器 (Gemma 4适配)
ComfyUI Node

PJ-JSON提示词提取器 (Gemma 4适配)

That structured JSON your LLM returned? This turns it into a usable prompt

By pongjoo·Created 7 months ago·Updated 3 days ago· 0
PJ-JSON提示词提取器 (Gemma 4适配)
    • 提示词文本
    JSON文本
    提取模式极简纯内容 (all_values)
    指定键名metadata_tags
    前缀文本
    后缀文本

    The most common way a local LLM ruins your prompt isn't being dumb - it's being chatty. You ask for a structured prompt, the model cheerfully wraps it in markdown, labels it with metadata_tags, and every bit of that scaffolding goes straight into your conditioning if nothing strips it. This is the "dirty, non-structured output" failure mode that every real prompt-node build fights (llm-in-comfyui.md documents the whole category). PJ_JSON_To_Prompt (pongjoo/ComfyUI-PJLatent, menu "PJ_Text") is the cleanup stage: you feed it the JSON an LLM emitted, it pulls out the actual prompt content, and outputs a clean, comma-joined string you can feed a text encoder.

    The display name says "Gemma 4 适配" because the author targets the structured JSON that Gemma-family chat models emit when asked for a prompt with a metadata_tags field - but it doesn't care which model produced the JSON. Any node that outputs JSON works: an in-graph LLM node, a captioner, even pasted text.

    The inputs:

    • JSON文本 - the raw JSON, multiline. It even strips stray ```json fences before parsing, which is the single most common piece of LLM litter.
    • 提取模式 - four ways to flatten, pick per use:
      • 极简纯内容 (all_values) - recursively walks the whole JSON and joins every scalar value with , . Keys dropped, values kept. The default, and usually what you want for a prompt.
      • 原样清理格式 (all_values_with_keys) - the no-parse escape hatch: strips quotes/braces/brackets line by line. Robust even when the "JSON" isn't valid JSON.
      • 精简标签列表 (metadata_tags) - specifically pulls the metadata_tags array (or whatever that key holds) and comma-joins it. Built for tag-based anime prompts where the LLM is asked to emit booru-style tags.
      • 提取指定键 (specific_key) - grabs one key of your choosing; the 指定键名 field even supports dotted paths like prompt.text for nested objects.
    • 前缀文本 / 后缀文本 - optional text prepended/appended to the result, joined with , . Your quality-tag prefix slot, effectively.

    If the input fails to parse as JSON entirely, there's a regex fallback that harvests every : "value" pair rather than erroring out - a nice touch, because LLMs lie about valid JSON all the time. One 提示词文本 string comes out the end.

    How to use it well. This is the second half of the chained-prompt pattern the community converged on: ask the LLM for structured output, then translate it into model-appropriate text. For an anime base you get it to emit {"metadata_tags": [...]}, route that JSON through the metadata_tags mode, and the node hands you a proper comma-separated Danbooru-style string. For natural-language bases, all_values flattens whatever fields it got. Either way, the node exists to make sure the model's formatting habits never reach the sampler.

    Install

    Part of pongjoo/ComfyUI-PJLatent (MIT). ComfyUI Manager → search "ComfyUI-PJLatent", or:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/pongjoo/ComfyUI-PJLatent.git
    

    Restart ComfyUI. No dependencies or model downloads - pure Python string work. Find it as PJ-JSON提示词提取器 under "PJ_Text", and pair its output with the same pack's PJTextCombine when you need to glue a prefix on.

    CategoryPJ_Text

    Inputs (5)

    NameTypeDefaultDescription
    JSON文本STRING
    提取模式COMBO极简纯内容 (all_values)4 options: 极简纯内容 (all_values), 原样清理格式 (all_values_with_keys), 精简标签列表 (metadata_tags), 提取指定键 (specific_key)
    指定键名STRINGmetadata_tags
    前缀文本optSTRING
    后缀文本optSTRING

    Outputs (1)

    NameTypeDescription
    提示词文本STRING