Qwen Thinking Prompt (Before KSampler)
Let a 4B Reasoning Model Polish Your Prompt Before the KSampler
- model
- tokenizer
- refined_prompt
- thinking
This is the half of the Qwen-llm-loader pack you'll actually fiddle with. The display name - "Qwen Thinking Prompt (Before KSampler)" - tells you exactly where it sits: between the loader and your KSampler path, turning your rough idea into a clean prompt before the image model ever sees it.
You feed it a messy raw prompt and it hands back a structured one. The default instruction_body is a ready-made prompt-engineering brief: preserve the original meaning, don't invent concepts, remove redundancy, output a single comma-separated line, no extra text. That's the whole point - it does the cleanup you'd otherwise do by hand or by copy-pasting into a chatbot, only it's local, in-graph, and re-runnable. No API, no key, no calls home. (If you've seen the horror stories about custom nodes phoning out, this one is clean - local_files_only=True on the loader side means the model never even tries to reach the internet.)
How it works
Two of its inputs are themselves prompts. prompt_body is the template with {instructions} and {user_prompt} placeholders; the default wraps everything in <think> ... </think> and a Final prompt: marker. The node formats that template, runs model.generate, then does some parsing: everything after the last Final prompt: becomes refined_prompt, and whatever the model wrote inside <think>...</think> becomes the thinking output. So the "visible chain-of-thought" is literally a text block you can pipe to a ShowText node and inspect.
The inputs that matter
- user_prompt - your raw idea. The only thing you'll type most runs.
- instruction_body - the rules block. This is where you customize. Tag-based models want "emit Danbooru tags, comma-separated"; an LLM-encoded model like Z-Image wants a natural-language sentence structure. The default suits the latter.
- max_new_tokens - cap of 512, default 256. If the model rambles, the final prompt can get cut off; bump it when output looks truncated.
- temperature / top_p - defaults 0.6 / 0.85 are a good middle ground. Lower temperature for consistent rewrites, raise it if every run gives the same boring prompt.
- prompt_body - the template. Leave it alone until you understand the marker parsing; break the
Final prompt:marker and you'll get raw model text instead of a clean line.
What wires where
refined_prompt(STRING) → your positive prompt conditioning → KSampler.thinking(STRING) → a ShowText node if you want to see the reasoning.
Both need model and tokenizer from the Qwen Thinking Loader node in the same pack - there's no other way to feed this node, so install them together. Install steps and the model download live in the loader's page, but the short version: Manager → search "Qwen-llm-loader", clone, restart, then drop the Qwen3-4B-Thinking-2507 files into ComfyUI/models/qwen/<folder>/.
Where people get burned
Truncation is the most common one - a long instruction_body plus a long prompt eats the token budget fast, so keep the rules tight. If refined_prompt comes back empty or weird, check whether your edited template still ends with a Final prompt: marker, because that's what the extraction keys on. And remember this node is a standalone prompt refiner, not a drop-in text encoder: the same author plays with Qwen3-4B-Thinking as a Z-Image text encoder, but that's a different workflow from the one these two nodes run. One aside: on LLM-encoded models this whole pattern stops being a hack - the image model's encoder reads your prompt as a message, so having an LLM write it is just translation between speakers of the same language.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| model | QWEN_THINKING_MODEL | — | |
| tokenizer | QWEN_TOKENIZER | — | |
| user_prompt | STRING | — | |
| prompt_body | STRING | <think> {instructions} User prompt: {user_prompt} Final prompt: </think> Final prompt: | — |
| instruction_body | STRING | You are an expert Stable Diffusion prompt engineer. Rules: - Preserve the exact original meaning and intent. - Do NOT add any new concepts, styles, subjects, or details not present or implied. - Remove redundancy and make the prompt concise but descriptive. - Structure as a single, clean, comma-separated line. - Output ONLY the final prompt. No reasoning, no extra text. | — |
| max_new_tokens | INT | 25632–512 | — |
| temperature | FLOAT | 0.600.1–1.2 | — |
| top_p | FLOAT | 0.850.1–1 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| refined_prompt | STRING | — |
| thinking | STRING | — |