Extract Q/A (CRT)
The node that turns a JSON Q/A pair into a prompt an LLM can finish
- phrase
- instruction
You probably got here because you downloaded a workflow that's generating Q/A training data with a local LLM. The pack ships one literally called "QA Pairs LLM Distillation Finetuning," and Extract Q/A (CRT) is its front end: it takes a JSON string holding one question-and-answer pair, pulls one side out, and wraps it in a canned instruction that a language model can finish. It's the "read the pair, decide what's missing" step.
The name undersells the mechanism, which is boring in the best way. The node parses your {"user":"...","assistant":"..."} string with json.loads, grabs one field, and formats it into a hard-coded prompt template. No API, no key, no model - pure string surgery. That's the whole job, and it does it deterministically.
The one input you actually set is target, a boolean that reads a little backwards at first. ON (the default) extracts the user question and builds an "answer it" instruction - literally Answer the following question accurately and concisely: followed by the question. OFF extracts the assistant answer instead and builds a "create the question" instruction (Write a clear, concise question that would be directly answered by the following text:). So the toggle isn't "which field to edit," it's "which side do you have, and which side do you want the LLM to produce."
qa_string is marked forceInput, which is the author's way of saying: don't type this, wire it in. In the QA workflow it comes from Text Rows Crawl (CRT), which hands it one row at a time from a multiline list.
Two outputs come out:
phrase- the raw extracted text, in case another node needs it.instruction- the finished prompt, ready to feed into the pack'sUnsloth Studio Bridgenode (the CRT/LLM node that talks to a local Unsloth Studio server). That's the intended consumer; you could equally route it to any LLM-in-the-graph node you run.
Then the loop completes: the LLM's answer flows into Merge Q/A (CRT), which slots it back into the JSON, and Text Add Rows (CRT) logs the finished row to a text file. Extract QA is only the first third of that chain, but without it the chain has nothing to send.
Where people get burned: feed it malformed JSON and it doesn't crash - it returns empty strings and prints [ERROR] Extract Q/A (CRT): invalid JSON input to the console. If your workflow silently produces empty text, that's where to look. It also won't complain if the field you asked for is missing; you just get "". And if you're digging through old workflow files, note the node has backward-compat handling for an older string-based target ("user"/"assistant") and an even older boolean name - so old graphs still load, which is more than most packs bother with.
Install it as part of CRT-Nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/PGCRT/CRT-Nodes
Then restart ComfyUI. ComfyUI Manager users can just search "CRT-Nodes." One honest caveat: the pack's requirements.txt is heavy (transformers, opencv, whisper, librosa…) because the audio and model nodes need it - this text node needs none of it. If you only want the CRT/Text nodes, clone manually and skip pip install -r requirements.txt; if you install via Manager, it pulls everything regardless. The trade is yours.
The pack itself is the work of a single developer (PGCRT, "Kornesh Kanan" in git) who's reasonably active on r/StableDiffusion and responsive to issue reports - it earned its reputation on early Z-Image Turbo LoRA support and audio/video utilities, and this text corner is the same honest plumbing. For a Q/A dataset pipeline it's the right tool, because it does exactly one thing and does it every run.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| qa_string | STRING | JSON string in the form {"user":"...","assistant":"..."} | |
| target | BOOLEAN | true | ON = extract the user question and build an 'answer it' instruction. OFF = extract the assistant answer and build a 'create the question' instruction. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| phrase | STRING | — |
| instruction | STRING | — |