Save 4 hours! We auto-setup your workflow! Free!

Drop your workflow.json — we handle every dependency, custom node, and model. Just open the link and run.

Auto-Setup Workflow Json (Free) Now!
ComfyUI > Nodes > ComfyUI-String-Function > LM Studio Prompt Generator

ComfyUI Node: LM Studio Prompt Generator

Class Name

SFn_LMStudioPromptGenerator

Category
String Function
Author
takkunred (Account age: 0days)
Extension
ComfyUI-String-Function
Latest Updated
2026-11-03
Github Stars
0.0K

How to Install ComfyUI-String-Function

Install this extension via the ComfyUI Manager by searching for ComfyUI-String-Function
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI-String-Function in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

LM Studio Prompt Generator Description

Turns image concepts into generation prompts via LM Studio, with optional negative prompts.

LM Studio Prompt Generator:

SFn_LMStudioPromptGenerator turns an image concept into a prompt using a language model served by LM Studio. It sends your concept and instructions to the model, then attempts to extract an image-generation prompt and, when requested, a negative prompt from the reply. It can ask LM Studio for a structured JSON response or work with a text response, making it useful when you want to develop prompt ideas within a node workflow. The result still depends on the model’s response: the node reports whether it successfully extracted a prompt rather than assuming every reply is usable.

LM Studio Prompt Generator Input Parameters:

theme

The image concept you want the model to develop. Write the subject, setting, mood, style, or other details you care about, such as “a quiet greenhouse at dawn, watercolor illustration.” This is a required, multiline text field with an empty-string default; no length limit is specified. If it is empty or contains only spaces, the node returns empty text outputs and does not contact LM Studio.

system_prompt

Instructions that guide how the model develops your concept. This required, multiline text field defaults to the node’s built-in DEFAULT_SYSTEM_PROMPT, whose wording is not included in the provided source; no length limit is specified. Use it to communicate creative priorities or constraints. You do not need to add the node’s output-format instructions yourself: it supplies a JSON schema in structured mode or appends a text-format hint in text mode.

model_key

The LM Studio model key to use. This required text field defaults to an empty string; no length limit is specified. When left blank, the node looks for a loaded language or vision-language model. If it cannot identify one, it omits the model key from the request and leaves model selection to the server. Enter a specific key when you need to target a particular model.

structured_output

Controls how the node requests the reply format. This required Boolean has two options: True (default) requests JSON matching a schema for the prompt fields, while False asks for text and then attempts to extract the fields from that text. Structured mode is the source’s recommended setting, though the model and server must still return usable content; if JSON prompt extraction fails, the node tries its normal prompt extractor.

generate_negative

Controls whether the model is asked to create a negative prompt alongside the main prompt. This required Boolean defaults to True. With True, the JSON schema requires a negative_prompt field in structured mode, or the node adds an appropriate format hint in text mode, and it attempts to extract that field. With False, the node does not request or extract a negative prompt, and its corresponding output is empty.

seed

A number sent with the request to influence model generation. This required integer defaults to -1; its allowed range is -1 through 18446744073709551615. At -1, the node chooses a random seed on each execution and marks itself as changed so it can run again. A fixed value supports more consistent reruns, although the source does not guarantee identical model responses. The value sent to LM Studio is reduced modulo 2147483647.

max_tokens

The maximum number of tokens requested for the model’s reply. This optional integer defaults to 4096, with a minimum of 1 and maximum of 131072. Increase it if replies are being cut short; lower it when you want to limit response length. A very small limit may leave too little room for a complete prompt or structured reply.

temperature

A model-generation setting that influences variation in the reply. This optional float defaults to 0.7, ranges from 0.0 to 2.0, and changes in 0.05 steps. Lower values are useful when you want more restrained results; higher values can encourage variation. The exact effect depends on the model served by LM Studio.

auto_unload

Controls whether the node requests that the model be unloaded after use. This optional Boolean defaults to False. When enabled with unload_delay set to 0, the node attempts an immediate unload after the chat request, including when that request raises an error. With a positive delay, it sends a time-to-live value in the request instead. Use this setting when freeing model memory matters more than keeping the model ready for another run.

unload_delay

The requested time-to-live, in seconds, when auto_unload is enabled. This optional integer defaults to 0 and ranges from 0 to 3600. At 0, the node attempts to unload immediately after the request; above 0, it includes the delay as a ttl value for LM Studio rather than calling its immediate-unload routine. It has no effect while auto_unload is False.

timeout_seconds

How long, in seconds, the node waits for the chat request before it times out. This optional integer defaults to 300 and ranges from 10 to 3600. Increase it for a model that needs more time to respond; a timeout does not by itself indicate that your concept or prompt instructions are invalid.

strip_thinking

Controls which version of the model reply appears in raw_text. This optional Boolean defaults to True. With True, raw_text uses the text after the node’s preprocessing step, which is intended to remove thinking blocks. With False, raw_text preserves the original returned content. Prompt extraction uses the preprocessed text in either case; the provided source does not specify every pattern removed by preprocessing.

debug

Enables diagnostic printing. This optional Boolean defaults to False. When enabled, the node prints request information, the selected loaded-model key when it looks one up, and the model response to the application log. This can help you diagnose formatting and connection problems, but the logs may contain your concept, instructions, and generated text.

LM Studio Prompt Generator Output Parameters:

prompt

The image-generation prompt extracted from the model reply, returned as a string. This is the primary result to pass to the next part of your image workflow. It is empty when the concept contains no non-space text or when extraction does not produce a prompt; check success before relying on it.

negative_prompt

The extracted negative prompt, returned as a string for workflows that accept elements to avoid. It is empty when generate_negative is False or when no negative prompt can be extracted. A successful main prompt does not, by itself, establish that this field was populated.

raw_text

The model’s reply, returned as a string so you can inspect what was actually generated. By default it is the preprocessed version; set strip_thinking to False to receive the original returned content instead. This output is especially helpful when prompt is empty or differs from what you expected.

method_used

A string indicating the extraction method reported for the main prompt. The source explicitly uses json when structured JSON prompt extraction succeeds and empty when an empty concept stops execution; other values come from the separate prompt extractor, whose implementation is not provided here. Read this alongside success and raw_text when troubleshooting.

success

A Boolean indicating whether the node’s main prompt extraction succeeded. False is returned for an empty concept and may also be returned when the model’s reply cannot be extracted into a prompt. It does not certify the artistic quality of the prompt or confirm that negative_prompt is present.

LM Studio Prompt Generator Usage Tips:

  • Start with a concrete theme that names the subject and a few visual priorities. Put reusable creative instructions in system_prompt so you can change the concept without rewriting those instructions.
  • Keep structured_output at its default True when your LM Studio model supports the requested JSON response. If a model produces unusable structured replies, try False and inspect raw_text and success.
  • Leave model_key blank when you want to use a loaded model. Specify its key when you need to target a particular model; if none is identified while the field is blank, model selection is left to LM Studio.
  • Use generate_negative=False when your downstream workflow does not need a negative prompt. When it is enabled, check the negative_prompt output independently because success only reports main-prompt extraction.
  • Use a fixed seed when comparing prompt instructions or temperature settings; keep -1 when you want a new random seed on each execution.
  • If replies appear incomplete, raise max_tokens. If generation times out, increase timeout_seconds within its allowed range. Turn on debug briefly when you need to inspect request and response details in the application log.
  • LM Studio’s connection address can be set through LMSTUDIO_BASE_URL in the environment or a .env file beside the node module. The environment value takes precedence; the default is http://localhost:1234. The node reads the .env file on each configuration lookup, so changes to that file do not require a restart for this node to read them.

LM Studio Prompt Generator Common Errors and Solutions:

LM Studio に接続できません (<base URL>): <details>

  • Explanation: The chat request could not reach LM Studio or did not complete before the timeout. The source raises this message for connection, timeout, and related operating-system errors.
  • Solution: Confirm that the LM Studio server is running and that LMSTUDIO_BASE_URL points to it. For a remote server, check LM Studio’s local-network serving setting and your firewall. If a slow model is responding but needs more time, increase timeout_seconds.

LM Studio がエラーを返しました (HTTP <code>): <details>

  • Explanation: LM Studio received the request but returned an HTTP error. The node includes up to 500 characters of the server’s error details, so the precise cause depends on that message.
  • Solution: Read the details first. Check that the requested model is available, that the server accepts the request settings, and, when using structured output, that your model and server can handle the requested JSON schema. Adjust the setting identified by the server and retry.

LM Studio の応答形式が不正です: <response excerpt>

  • Explanation: The returned data did not contain a usable chat message in the response structure expected by the node.
  • Solution: Check that LMSTUDIO_BASE_URL points to an LM Studio server offering the chat-completions endpoint, rather than an unrelated service or page. Inspect the response excerpt and verify the server configuration before retrying.

Empty output with method_used set to empty and success set to False

  • Explanation: If theme is blank or contains only spaces, the node stops before contacting LM Studio and returns empty strings, empty, and False.
  • Solution: Enter a non-empty image concept in theme and run the node again.

An empty prompt with success set to False after a response

  • Explanation: The node received content but could not extract a main prompt from the preprocessed reply. In structured mode, it tries JSON extraction first and then its normal prompt extractor.
  • Solution: Inspect raw_text to see what the model returned. Make your system_prompt clearer, allow enough room with max_tokens, or try switching structured_output to test whether your model responds better in the other format.

An empty negative_prompt despite a generated prompt

  • Explanation: The negative output remains empty when generate_negative is disabled or when negative-prompt extraction finds nothing. Main-prompt success does not guarantee a negative prompt.
  • Solution: Enable generate_negative if you need this field, then inspect raw_text to confirm whether the model actually supplied negative-prompt content.

[SFn LMStudio] アンロードに失敗: <details>

  • Explanation: With immediate automatic unloading enabled, the node could not unload the model through either of its attempted methods. It prints this diagnostic message; the unload routine does not raise it as a generation error.
  • Solution: Check that model_key identifies the intended model and that the LM Studio connection supports model unloading. If immediate unloading is not essential, turn off auto_unload or use a positive unload_delay to request time-to-live behavior instead.

LM Studio Prompt Generator Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI-String-Function
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Models, enabling artists to harness the latest AI tools to create incredible art.

LM Studio Prompt Generator