"Temperature 0 makes the AI a deterministic function — same input, same output, every time."
When a salesperson submits an RFQ, the concrete mixture proportions are validated by GPT-4o before the quotation enters the approval queue. The AI returns structured JSON. Below 35% OPC cement triggers a soft warning; an invalid mixture combination is a hard block.
Part of the Green Concrete ERP project. View full project page →
System Prompt Design for Structured Output
The key to reliable AI validation is a system prompt that defines an exact JSON contract. The AI must return JSON — nothing else. No markdown, no explanations wrapped around the JSON.
private const string SYSTEM_PROMPT = @"
You are a concrete mixture validation expert for Saudi construction standards.
Analyze the mixture proportions and return ONLY this JSON:
{
""valid"": true/false,
""severity"": ""ok"" | ""warning"" | ""block"",
""reason"": ""one sentence"",
""suggestion"": ""one sentence or null""
}
Rules:
- OPC percent below 35: severity=warning
- OPC percent below 20 or physically impossible mix: severity=block
- Do not include any text outside the JSON object.
";AiMixtureValidationService — Full Implementation
public async Task<MixtureValidationResult> ValidateAsync(
List<MaterialRow> rows, CancellationToken ct)
{
try
{
var userMessage = "Mixture: " + BuildMixtureDescription(rows);
var options = new ChatCompletionsOptions
{
DeploymentName = _cfg["AzureOpenAI:DeploymentName"],
Temperature = 0,
MaxTokens = 300,
};
options.Messages.Add(new ChatRequestSystemMessage(SYSTEM_PROMPT));
options.Messages.Add(new ChatRequestUserMessage(userMessage));
var response = await _client.GetChatCompletionsAsync(options, ct);
var json = response.Value.Choices[0].Message.Content;
return JsonSerializer.Deserialize<MixtureValidationResult>(json)!;
}
catch
{
// AI unavailable — allow submission, note in result
return new MixtureValidationResult
{
Valid = true, Severity = "ok",
Reason = "AI validation unavailable — review manually"
};
}
}Soft Warning vs Hard Block
Soft warning (severity: warning): The RFQ form shows a yellow warning box with the reason and suggestion. The salesperson must tick "I confirm this mixture is intentional" before submitting. The quotation enters the approval queue with a warning flag visible to the manager.
Hard block (severity: block): The form shows a red error box and the Submit button is disabled. The salesperson cannot proceed — they must fix the mixture. The reason and suggestion are shown.
AI unavailable (catch block): Returns severity: ok with a note. The quotation proceeds normally. The manager sees "AI validation unavailable" in the quotation details and makes the judgment call. Never let an AI service outage stop the business.
🎯 Quick Check
Q1: Why set Temperature=0 for the validation AI call?
Show Answer
Temperature=0 makes the AI deterministic — the same mixture proportions will always produce the same validation result. For a validation function, we need consistency and predictability. Temperature > 0 introduces randomness which would cause the same mixture to sometimes pass and sometimes fail, which is unacceptable in a business process.
Q2: Why does the catch block return severity: ok instead of severity: block when the AI is unavailable?
Show Answer
Failing open (allowing the request through) is better than failing closed (blocking the business) when the failure is in a non-critical dependency. The AI validator adds value but is not the primary gatekeeper — the human manager approval workflow is. If we fail closed, an Azure OpenAI outage stops all RFQ submissions, which is unacceptable. The manager can manually verify the mixture during approval.
Q3: What makes the system prompt effective for structured JSON output?
Show Answer
Three things: (1) Specify ONLY JSON — no markdown wrapper, no explanation text. (2) Define the exact schema with field names, types, and allowed values. (3) State the business rules explicitly (OPC below 35 = warning, OPC below 20 = block). The more specific the prompt, the more reliably the model returns parseable output.
Key Takeaways
- Temperature=0 makes AI responses deterministic — essential for validation functions
- System prompt defines the JSON contract — always specify the exact schema and all business rules
- Soft warning requires human confirmation; hard block prevents submission until fixed
- AI unavailable falls open (allows submission) — never let an AI outage stop the business
- The validation result travels with the quotation through the approval workflow so managers can review AI flags