Mistral AI prompt loader
A JSON file reader that makes your Mistral calls smarter
- few_shot_prompt
LoadFewShotPrompt is not going to blow your mind. It reads a JSON file and outputs its contents as a string. That's the whole node - but it's the missing half of the pack, because it's what turns the "Mistral AI completion" node from a blunt prompt-writer into something that actually understands your prompting style.
It ships in randomnoner11/ComfyUI-MistralAI-API alongside InvokeMistralEndpoint, and the two are designed to be wired together. The loader's output, few_shot_prompt, feeds directly into the completion node's context input. That context is what makes few-shot prompting possible: instead of telling Mistral "write me a prompt," you hand it a few examples of the kind of output you want, and it imitates the pattern. It's the same trick as showing a human a sample of work before asking them to produce more.
How it works
On startup the node registers a folder named prompts inside the pack's directory and lists every .json file in it. That list is your prompt_file dropdown. Pick one and the node reads the file and returns the raw text - no parsing, no validation, just file.read(). If the read fails, you get an empty string and a console message, not a crash.
The three example files that ship with it are worth reading once, because they encode a real choice about prompting strategy. example-tags.json asks for comma-separated Danbooru tags, which is what SDXL-lineage checkpoints (Illustrious, NoobAI, Pony) eat for breakfast. example-natural-lang.json asks for flowing descriptive prose, the right call for the newer LLM-encoded models whose text encoders want instructions and sentences, not a token bag. example-natural-w-tags.json splits the difference - natural language with tags mixed in. The message arrays follow the standard chat format: system instructions, then alternating user/assistant pairs showing exactly the transformation you want the model to copy.
Wiring it up
Only two things to know in the graph:
prompt_file- pick from the dropdown. To add your own, drop a JSON file with an array of{"role": ..., "content": ...}messages intoComfyUI/custom_nodes/ComfyUI-MistralAI-API/prompts/and restart ComfyUI; it'll appear in the list.few_shot_prompt(output) - wire this into thecontextinput ofInvokeMistralEndpoint.
Install
Same story as its big sibling: this is a zero-dependency pack. Either clone it or grab it from ComfyUI Manager (search "MistralAI"):
cd ComfyUI/custom_nodes
git clone https://github.com/randomnoner11/ComfyUI-MistralAI-API
Restart ComfyUI and the node shows up under utils/text. No pip install, no model files, nothing to download. (Do remember the pack still needs your Mistral API key in API-key.txt - this node loads files, but it won't make the actual API call work on its own.)
Where people get burned
- It only sees files in its own
prompts/folder. The dropdown is built from exactly one directory. People drop JSON files next to their workflow and wonder why they don't show up. Path isComfyUI/custom_nodes/ComfyUI-MistralAI-API/prompts/. - No validation, ever. The README says it plainly: the content isn't checked. If your JSON is malformed, the loader happily passes it along, and then
InvokeMistralEndpointfails to parse it, prints a warning, and just sends your prompt with no context. You'll get output that's worse than if you'd never used few-shot at all, with nothing in the UI telling you why. Console is where the truth lives. - Restart needed for new files. The file list is built at load time, so new JSON files require a ComfyUI restart to appear in the dropdown.
It's a thin node and that's fine - the author kept it to one job and did that job with zero surprises. If you're using the Mistral pack to write prompts, you'll reach for the loader the moment you want consistent output instead of whatever the model decides that day.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt_file | COMBO | 3 options: example-natural-lang.json, example-natural-w-tags.json, example-tags.json |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| few_shot_prompt | STRING | — |