Capabilities & guides
Prompt Engineering & JSON Output
Master system constraints, few-shot grounding, multi-step decomposition, and strict JSON formatting.
Updated 2026-11-26 · 2 min read
Anatomy of a Production Prompt
Reliable prompts separate system rules, untrusted reference context, explicit task steps, and output format contracts. Keeping instructions distinct from input data improves compliance and reduces prompt-injection surface area.
| Component | Purpose | Best Practice |
|---|---|---|
| System role & guardrails | Establish domain perspective and hard boundaries | State explicitly: "Use only supplied facts; return null when unknown" |
| Reference context | Supply retrieved chunks, tickets, or policy rules | Wrap raw user or document data inside clear delimiters |
| Task instructions | Define exact analytical or transformation steps | Use numbered steps rather than vague verbs like "improve this" |
| Output contract | Constrain structure, field types, and length | Provide an explicit JSON schema or a concise one-shot example |
Reusable Enterprise Extraction Template
Adapt this template for ticket triage, contract key-term extraction, or meeting-note synthesis:
You are a precise enterprise operations analyst. Extract structured fields strictly from the [SOURCE RECORD] below:
1. Rely only on explicitly stated facts; set any missing field to null.
2. Keep "summary" under 40 words in neutral, factual language.
3. Output a single valid JSON object with no surrounding prose.
Target JSON format:
{
"category": "incident | billing | feature_request",
"urgency": "high | medium | low",
"summary": "Concise issue summary",
"action_items": ["Action 1", "Action 2"]
}
[SOURCE RECORD]
Paste sanitized business text here...Enforcing Deterministic JSON Output
When downstream code parses model output programmatically, combine response_format with low sampling temperature and explicit field definitions:
response = client.chat.completions.create(
model="qwen4-max",
response_format={"type": "json_object"},
temperature=0.1,
messages=[
{
"role": "system",
"content": "Return a valid JSON object containing risk_level (low/medium/high) and an issues string array.",
},
{
"role": "user",
"content": "Change proposal: extend webhook signature window to 60 minutes and disable nonce replay checks.",
},
],
)Note: When using
json_objectmode, always include the wordJSONin your prompt messages so the model knows the exact target structure, and validate the parsed payload with Zod or Pydantic on your server.
Recommended Sampling Parameters
| Parameter | Recommended Range | Typical Use Cases |
|---|---|---|
temperature | 0.0 – 0.2 | Code generation, JSON extraction, classification, and grounded RAG Q&A |
temperature | 0.6 – 0.8 | Campaign copywriting, brainstorming, and creative concept variants |
max_tokens | Sized to expected output | Prevents runaway generation while leaving headroom for reasoning models |
Iterative Debugging Tips
- Prefer positive few-shot examples over long negative rules: One concrete input-output pair resolves formatting ambiguity faster than a dozen contradictory "do not" clauses.
- Decompose overloaded prompts: Split workflows that mix heavy extraction, arithmetic verification, and translation into focused sequential steps. To connect models to live APIs and databases, continue to Streaming & Function Calling.