LlmSetSystemPrompt Function  
 
BOOL WINAPI LlmSetSystemPrompt(
  HCLIENT hClient,  
  LPCTSTR lpszSystemPrompt  
);

The LlmSetSystemPrompt function changes the current system prompt for a client session.

Parameters

hClient
A handle to the client session.
lpszSystemPrompt
A pointer to a string buffer which will contain the new system prompt for the current session. If this parameter is NULL or an empty string, a system prompt will not be included with new requests.

Return Value

If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To get extended error information, call LlmGetLastError.

Remarks

A system prompt provides instructions that are included with each request sent to the model. It can be used to define the expected role, tone, response style, formatting rules, or other application-specific guidance that should apply to the session.

For example, an application might use a system prompt to request short responses, avoid Markdown formatting, return structured text, or answer only within the context of a specific feature or workflow.

Because conversation history is included with each request, messages that were generated using a previous system prompt may still influence subsequent responses. Changing or clearing the system prompt does not retroactively modify existing messages in the history. If the new prompt represents a significant change in behavior, applications may want to clear the history to avoid unintended interactions between the previous and current instructions.

If the new prompt represents a significant change in behavior, applications may want to call LlmClearHistory before sending additional messages.

The system prompt should be treated as guidance, not a guarantee. Different providers and models may interpret system instructions differently, and user messages may still influence the response. If lpszSystemPrompt is NULL or points to an empty string, the current system prompt is cleared and no system prompt will be included with new requests.

Support for system prompts may vary between providers and models. Some providers treat the system prompt as a distinct message role, while others incorporate it as part of a separate instruction field. The library will map the system prompt to the appropriate format for the selected provider, but the exact behavior and influence on the response may differ. Applications should test system prompt behavior with their selected provider to ensure it produces the desired results.

Note that some providers or models will not provide any support for a system role. This is more common with locally hosted models using applications like LM Studio or Ollama. To determine if a model supports system prompts, use the LlmGetModelFlags function and check for the LLM_MODEL_FLAG_SYSTEM_ROLE flag.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csllmv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also

LlmClearHistory, LlmGetModelFlags, LlmGetSystemPrompt, LlmResetSession, LlmSendMessage, LlmSendMessageEx