GPT-4.1 Prompting Guide
Prompting techniques specific to GPT-4.1. Covers agentic workflows, 1M token context, literal instruction following, and the planning patterns that boosted SWE-bench by 4%.
Official OpenAI docs →The big shift: literal instruction following
GPT-4.1 follows instructions more literally than any previous GPT model. This is a fundamental change. Vague prompts that 'kinda worked' before will underperform now. The upside: when you're specific, it nails it. The downside: you can't rely on the model inferring what you meant. If you're migrating from GPT-4 or GPT-4 Turbo, audit your prompts for anything ambiguous.
Building agentic workflows
Three components should appear in every agent prompt: Persistence ('keep going until the user's query is completely resolved'), Tool-calling ('do NOT guess or make up an answer without using your available tools'), and Planning (explicit reasoning between function calls). Use the API's tools field rather than manually injecting tool descriptions. Name tools clearly with detailed descriptions.
Prompting-induced planning
Even though GPT-4.1 isn't a 'reasoning model', you can induce explicit chain-of-thought through prompts. This improved SWE-bench Verified pass rates by 4%. The pattern: investigate thoroughly before implementing, make incremental changes with frequent testing, debug extensively and handle edge cases, then validate and reflect on the result.
1M token context handling
GPT-4.1 handles its full 1M token context with strong needle-in-haystack performance. For strict context-only responses, use: 'Only use the documents in the provided External Context.' Place instructions at both the beginning and end of long context for best results. If using a single instruction location, above the context performs better than below.
Instruction structure
Recommended prompt structure: Role and Objective, then Instructions, then Sub-categories, then Reasoning Steps, then Output Format, then Examples, then Context, then Final instructions. When instructions conflict, GPT-4.1 follows instructions closer to the end of the prompt. Development workflow: start with high-level 'Response Rules' bullet points, add category-specific sections, include ordered steps, debug by checking for conflicts, and add examples.
Code diffs and file editing
The guide includes a custom apply_patch tool for structured code modifications. Use context lines (surrounding code) to uniquely identify where changes go, rather than line numbers which break easily. Multiple @@ statements let you target deeply nested code. This approach is how OpenAI's own coding agents handle reliable file editing in agentic workflows.