Nodes/ComfyUI_LiteLLM/LiteLLMCompletionPrePend
ComfyUI Node

LiteLLMCompletionPrePend

The completion node with a system-prompt slot bolted on front

By Hopping-Mad-Games·Created 2 years ago·Updated 11 months ago· 7
LiteLLMCompletionPrePend
  • model
  • messages
  • Model
  • Messages
  • Completion
  • Usage
max_tokens250
temperature0.50
top_p0.50
frequency_penalty0.00
presence_penalty0.00
reasoning_effortlow
pre_promptpre
promptprompt
use_cached_responsefalse

LiteLLMCompletionPrePend is LiteLLMCompletion with one extra text box in front of it. That's the whole diff. Its handler takes your pre_prompt, joins it to your prompt with a newline, and passes the result down to the plain completion handler. Nothing else changes - same model handling, same caching, same retries, same outputs.

So why does it exist? Because in a graph UI, the "always say this before every prompt" text is a separate concern from the per-run prompt. You get a stable place for your standing instructions - "You are a senior prompt engineer. Return only JSON." - while the prompt field stays free for the actual request. It's a small quality-of-life split, and once you've built workflows with it, you'll miss it on the plain node.

The inputs

Everything LiteLLMCompletion takes, plus:

  • pre_prompt (multiline) - prepended to the prompt with a newline before the call.
  • model - LITELLM_MODEL from a provider node.
  • prompt (multiline), max_tokens (250), temperature / top_p (0.5), frequency_penalty / presence_penalty (0), reasoning_effort - the usual dials.
  • messages (optional) - conversation history to continue.
  • use_cached_response (optional) - replay the cached result.

Outputs: Model, Messages, Completion, Usage - identical to the base node.

How the prepending works

In the code it's one line: kwargs["prompt"] = f"{pp}\n{kwargs['prompt']}". The combined string becomes a single user message. That's worth knowing because it's not a system message and it's not two messages - it's one message where the instruction happens to come first. For most models that's fine and even preferable, but if you were expecting true system-role separation (some models behave differently when told "system: ..."), you won't get it here; use the messages input with a proper role instead.

Installing

It's part of ComfyUI_LiteLLM. ComfyUI Manager, search "ComfyUI_LiteLLM", or:

cd ComfyUI/custom_nodes
git clone https://github.com/Hopping-Mad-Games/ComfyUI_LiteLLM
cd ComfyUI_LiteLLM
pip install -r requirements.txt

Restart, set a provider key, and it's under ETK/LLM/LiteLLM.

Where people get burned

The trap is thinking the pre-prompt and prompt are sent as separate messages with different roles. They're not - it's a string concatenation with a newline. If you're debugging weird model behavior and you know the instruction text is in the call, check whether your model cares about message roles: if it does, splice your system text in via the messages input instead. Second, the same stale-model gotcha applies - the default is the ancient anthropic/claude-3-haiku-20240307, and a "model not found" error on a fresh install is the dropdown lying to you. Swap in a current model from LiteLLMModelProviderAdv or LiteLLMCustomEndpointProvider. And remember the cost reality: prepending instructions to every call means those tokens are billed on every single call. Keep the standing text tight, or you're paying for the same essay on repeat.

CategoryETK/LLM/LiteLLM

Inputs (11)

NameTypeDefaultDescription
modelLITELLM_MODELanthropic/claude-3-haiku-20240307
max_tokensINT2501–10000000000
temperatureFLOAT0.500–1
top_pFLOAT0.500–1
frequency_penaltyFLOAT0.00
presence_penaltyFLOAT0.00
reasoning_effortCOMBOlow3 options: low, medium, high
pre_promptSTRINGpre
promptSTRINGprompt
messagesoptLLLM_MESSAGES
use_cached_responseoptBOOLEANfalse

Outputs (4)

NameTypeDescription
ModelLITELLM_MODEL
MessagesLLLM_MESSAGES
CompletionSTRING
UsageSTRING