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.