ChatGPT and GPT-4 Prompting: Complete Strategies from the Prompt Engineering Guide

The Prompt Engineering Guide dedicates comprehensive sections to ChatGPT and GPT-4 prompting, covering message-based conversation formats, system message steering, JSON mode, function calling, and multimodal capabilities with production-ready code examples.

The dair-ai/Prompt-Engineering-Guide repository provides authoritative documentation on modern large language model prompting techniques. This guide examines how the repository specifically addresses ChatGPT and GPT-4 prompting strategies, from basic conversation patterns to advanced API features like deterministic outputs and parallel function calling.

ChatGPT Prompting Fundamentals

According to guides/prompts-chatgpt.md, ChatGPT is a conversational model trained with Reinforcement Learning from Human Feedback (RLHF) that excels at following instructions in dialogue form. Unlike legacy text-completion APIs such as text-davinci-003, ChatGPT uses a structured message-based protocol that fundamentally changes how prompts are constructed.

Message Roles and Conversation Format

The guide emphasizes that ChatGPT expects a sequence of messages with explicit roles: system, user, and assistant. In guides/prompts-chatgpt.md, the authors demonstrate how this format maintains conversation state across multiple turns, contrasting it with single-prompt completion models.

The following example from notebooks/pe-chatgpt-intro.ipynb shows a complete multi-turn conversation with explicit role assignment:

import openai

client = openai.OpenAI()

response = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are an AI research assistant with a technical tone."},
        {"role": "user",   "content": "Hello, who are you?"},
        {"role": "assistant", "content": "I am a technical AI assistant. How can I help?"},
        {"role": "user",   "content": "Explain how black holes form."},
    ],
    temperature=0.2,
)
print(response.choices[0].message.content)

System Message Steering

Recent OpenAI guidance documented in the repository recommends placing high-level instructions in the system message rather than the first user turn. This technique is particularly effective for snapshot models like gpt-3.5-turbo-0301, where the system message establishes persistent behavior across the entire conversation session.

The guide notes that encoding intent (what the bot does) and identity (tone/style) in the system message produces more consistent results than embedding these instructions in user prompts.

Advanced ChatGPT Capabilities

Beyond basic conversation patterns, the repository documents enterprise-grade features accessible through the Chat Completions API. These capabilities allow developers to build deterministic, tool-augmented applications.

JSON Mode and Deterministic Outputs

The guide details JSON mode, enabled via the response_format={"type": "json_object"} parameter, which guarantees valid JSON outputs from the model. Additionally, the repository explains deterministic outputs using the seed parameter and system_fingerprint fields to ensure reproducible results across API calls.

This approach eliminates manual parsing errors when integrating LLM outputs with downstream systems:

response = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "Always respond with valid JSON."},
        {"role": "user",   "content": "Give me three movie titles and their release years."},
    ],
    response_format={"type": "json_object"},
)
print(response.choices[0].message.content)  # {"movies": [{"title":"…","year":2020}, …]}

Function Calling and Parallel Execution

ChatGPT supports function calling and parallel function calls, allowing models to invoke external tools by generating structured JSON arguments. The guides/prompts-chatgpt.md file describes how to define tool schemas using the tools parameter and handle model-generated function arguments via tool_calls.

GPT-4 Prompting Techniques

The pages/models/gpt-4.en.mdx file documents GPT-4 as a large multimodal model supporting text and future image inputs. While GPT-4 shares the same message-based format as ChatGPT, it introduces significant enhancements in context length, reasoning capability, and multimodal potential.

Extended Context with GPT-4 Turbo

The GPT-4 Turbo variant (gpt-4-1106-preview) introduces a 128K token context window, enabling processing of extensive documents in a single request. This variant also adds JSON mode and parallel function calling, making it suitable for complex document analysis and long-form content generation tasks.

Multimodal Vision Capabilities

While the public API currently supports text inputs, the guide notes the roadmap for image inputs and demonstrates few-shot + chain-of-thought prompting strategies. These techniques prepare the model to reason over visual data such as charts and diagrams once multimodal capabilities become fully available.

System Message Persistence

Similar to ChatGPT, GPT-4 responds effectively to system messages that enforce output styles (e.g., "always output JSON"). However, the guide notes that GPT-4 requires less verbose instruction-heavy prompting compared to GPT-3 models, as high-level instructions in the system message persist naturally across conversation turns with greater reliability.

The following example demonstrates GPT-4 Turbo with enforced JSON output:

response = client.chat.completions.create(
    model="gpt-4-1106-preview",
    messages=[
        {"role": "system", "content": "You are an AI assistant that always outputs JSON."},
        {"role": "user",   "content": "Generate 5 sentiment‑labeled sentences."},
    ],
    response_format={"type": "json_object"},
    temperature=0.0,
)
print(response.choices[0].message.content)

Function Calling Implementation

Both models support external tool integration, though GPT-4 offers enhanced reliability. The repository provides complete implementations in notebooks/pe-chatgpt-langchain.ipynb demonstrating how to handle function definitions and execute model-generated calls.

This example shows the complete function calling workflow with GPT-4:

def get_weather(city: str) -> str:
    # placeholder – real implementation would call a weather API

    return f"Sunny in {city}"

response = client.chat.completions.create(
    model="gpt-4-1106-preview",
    messages=[{"role": "user", "content": "What’s the weather in Tokyo?"}],
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "description": "Returns the current weather for a city.",
                "parameters": {
                    "type": "object",
                    "properties": {"city": {"type": "string"}},
                    "required": ["city"],
                },
            },
        }
    ],
)

# The model may return a function call:

if response.choices[0].message.tool_calls:
    tool = response.choices[0].message.tool_calls[0]
    args = tool.function.arguments
    result = get_weather(**json.loads(args))
    print(result)

Summary

  • The Prompt Engineering Guide provides model-specific documentation for ChatGPT in guides/prompts-chatgpt.md and GPT-4 in pages/models/gpt-4.en.mdx.
  • ChatGPT prompting relies on structured message roles (system, user, assistant) and benefits from system-message steering for consistent conversational behavior.
  • GPT-4 prompting extends these patterns with larger context windows (128K tokens in Turbo variants), more reliable reasoning, and upcoming multimodal capabilities.
  • Both models support JSON mode (response_format) and deterministic outputs (seed parameter) for production integrations.
  • Function calling enables integration with external APIs, with GPT-4 offering enhanced reliability and parallel execution support compared to earlier models.

Frequently Asked Questions

What is the primary difference between ChatGPT and GPT-4 prompting?

According to the Prompt Engineering Guide, both models utilize the same message-based conversation format with system, user, and assistant roles. However, GPT-4 supports significantly larger context windows (128K tokens in GPT-4 Turbo), demonstrates superior performance on professional benchmarks, and offers more reliable function calling. ChatGPT excels at conversational tasks while GPT-4 handles complex reasoning, long-document analysis, and multimodal inputs more effectively.

How do I enforce consistent JSON output in ChatGPT and GPT-4?

Both models support JSON mode by setting response_format={"type": "json_object"} in the API request parameters. The guide recommends combining this with a system message explicitly stating "Always respond with valid JSON" to ensure consistent formatting. This approach works reliably in both ChatGPT and GPT-4 Turbo variants, eliminating the need for manual output parsing or regex validation.

Why is the system message important for ChatGPT prompting?

The system message establishes the model's behavior, identity, and constraints across the entire conversation session. The Prompt Engineering Guide emphasizes placing high-level instructions (such as tone requirements or output format rules) in the system message rather than user prompts. This technique is particularly important for snapshot models like gpt-3.5-turbo-0301 and reduces token usage compared to the instruction-heavy prompts required for GPT-3 models.

Does GPT-4 handle function calling differently than ChatGPT?

While both models support function calling through the Chat Completions API, GPT-4 (particularly gpt-4-1106-preview) offers improved reliability and supports parallel function calls. The guide demonstrates that GPT-4 more accurately selects appropriate tools and populates complex parameter schemas, making it preferable for multi-step workflows requiring precise tool orchestration.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →