System Instructions vs. JSON Schema
You DON’T need “always output in JSON schema” when using response_format={“type”: “json_object”}. The API parameter handles this automatically, so you can focus on writing clear, natural instructions.
Better approach: Use natural, human-like language in your system prompt, then let the JSON schema handle the structure.
System Instructions: Natural vs. Programming-like
Use natural language - it works much better:
python
#
GOOD - Natural, human-like
system_prompt = “”"You are an AI shell helper. Analyze the user’s request and determine the best response type.
If the user needs a shell command, provide it in the shell_command field.
If the user needs general help or conversation, provide it in the chat_response field.
Consider the context and user’s intent carefully.“”"
#
AVOID - Too programming-like
system_prompt = “”"Set shell_command to a value when shell command is needed.
Set chat_response to a value when general chat is needed.“”"
SON Schema Design
Field names DO matter - use descriptive, semantic names that help the model understand the purpose:
schema = {
“type”: “object”,
“properties”: {
“shell_command”: {
“type”: “string”,
“description”: “The shell command to accomplish the task, if applicable. Leave empty if no shell command is needed.”
},
“chat_response”: {
“type”: “string”,
“description”: “A helpful response when no shell command is needed, or additional context about the shell command.”
}
},
“required”: [“shell_command”, “chat_response”]
}
Think of it this way:
The descriptions should complement, not repeat, your system instructions. They give the model field-specific context about what belongs in each field.
Think of it this way:
The descriptions should complement, not repeat, your system instructions. They give the model field-specific context about what belongs in each field.
If Using JSON Mode (Legacy Approach)
You absolutely need JSON guidance in your system prompt:
python
system_prompt = “”"You are an AI shell helper. Analyze the user’s request and determine the best response type.
CRITICAL: You must ALWAYS respond with valid JSON in this exact format:
{
“shell_command”: “the command or empty string”,
“chat_response”: “helpful response or empty string”
}
Do not include any text outside the JSON object. Only output the JSON.“”"
#
This won’t work reliably with JSON mode
system_prompt = “”“You are an AI shell helper. Provide shell commands when needed, or helpful conversation when not.”“”
f Using response_format Parameter (Modern Approach)
You can focus on natural language without heavy JSON instructions:
system_prompt = “”"You are an AI shell helper. Analyze the user’s request and determine the best response type.
If the user needs a shell command, provide it in the shell_command field.
If the user needs general help or conversation, provide it in the chat_response field.
Consider the context and user’s intent carefully.“”"
Use response_format={“type”: “json_object”} instead of JSON mode because:
I had the Ai use some of my project examples to write this up, it explains things better than I do lol.