Best practices
This section outlines recommended approaches for creating, configuring, and managing AI-powered tasks effectively using the K2 Intelligence AI feature. Following these practices will help ensure consistent, reliable, and predictable outcomes. See Windows service and K2 Intelligence service for more information.
Create effective system prompts
Define prompts clearly and precisely. Avoid ambiguity and ensure the model understands its primary objective.
- Start with a clear instruction that defines the model’s purpose.
- Use structured techniques such as chain-of-thought or few-shot prompting where appropriate.
- Specify constraints such as length, format, or tone when required. Place critical instructions at the beginning and reinforce key expectations at the end.
- Avoid unnecessary roles or overly descriptive titles that do not add value.
Structure prompts to align with how smaller models process information:
First line: Clearly define the model’s single purpose using precise, unambiguous language. Avoid vague wording and unnecessary roles or titles.
Middle section: Provide the core instructions, steps, and guidelines that guide reasoning and task execution.
Closing line: Reinforce key expectations with explicit instructions. Limit focus to a few critical points and clearly define the required output format, especially when schema enforcement is not used.
Example
You are a sentiment analysis assistant. Analyze the sentiment of the provided text by following these steps:
- Identify the emotionally significant words or phrases in the text.
- Consider the overall tone: is it favorable, unfavorable, or neither?
- Classify the sentiment as positive, negative, or neutral.
- Summarize your reasoning in one sentence.
- Positive: expresses approval, happiness, satisfaction, or optimism
- Negative: expresses disapproval, sadness, frustration, or criticism
- Neutral: expresses facts or balanced views with no strong emotional lean
Design output fields
Define output fields carefully to improve response accuracy and consistency.
- Use clear and descriptive field names
-
Only set IsRequired when necessary, as using it unnecessarily may result in unintended or fabricated values.
- Select appropriate LogicalTypes that align with the expected data.
- Provide concise descriptions to guide the model, ensuring they complement (rather than duplicate) the prompt.
Input sanitization
Sanitize all external inputs to improve reliability and security.
- Enable SanitizeUserMessage for inputs originating from users or external systems (for example, forms, emails, documents).
- This reduces the risk of prompt injection attacks and improves text normalization.
- Disable sanitization only when exact input formatting must be preserved (for example, code or special characters).
Sanitization is a lightweight operation and does not significantly impact performance.
Choose schema enforcement
Select the appropriate schema enforcement method based on the use case:
- ResponseFormat: Use when available for best reliability.
- PromptInjection: Provides broader compatibility across providers. Structured output is still parsed automatically.
- Both:Use when additional reliability is required or when testing reveals inconsistent outputs.
- None: Suitable for simple, unstructured text responses.
Even when only a single output value is required, schema enforcement can improve response quality through field-level guidance.
Temperature settings
| Range | Behavior | Best For |
|---|---|---|
| 0.0 - 0.3 | Very focused and deterministic | Data extraction, factual responses |
| 0.4 - 0.7 | Balanced creativity and reliability | General purpose tasks |
| 0.8 - 1.0 | More creative and varied | Brainstorming, creative writing |
| 1.1 - 2.0 | Highly creative and random | Exploratory or experimental tasks |