How AI Decides When to Show You Code vs Explanation

One Two Three AI — in your inbox

AI news, practical tips and how-to guides. One useful idea a day.

How AI Decides When to Show You Code vs Explanation
Image generated with AI

Ask ChatGPT, Claude, or Gemini to help with code, and you’ll notice something curious: sometimes the model writes a full code block you can copy. Other times it explains the concept in plain English. And sometimes it does both, or switches mid-conversation without you asking.

This isn’t random. AI models follow patterns—learned from training data and shaped by system instructions—that determine when to show code, when to explain it, and when to do both. Understanding how these decisions get made helps you get the format you actually need.

Training Data Shapes the Default Response

Large language models learn how to respond to coding questions by studying millions of examples from GitHub, Stack Overflow, documentation sites, and technical forums. These sources have their own conventions: Stack Overflow answers often start with explanation, then provide a code snippet. GitHub issues might show code first, then discuss why it works. Documentation tends to explain concepts before showing implementation.

The model absorbs these patterns during training. When you ask a coding question, it predicts the most likely response format based on how similar questions were answered in its training data. A question phrased like a Stack Overflow post (“How do I reverse a string in Python?”) tends to get a Stack Overflow-style answer: brief explanation, then code. A question that sounds like a bug report (“My function returns None instead of the reversed string”) often gets troubleshooting-style responses with inline code suggestions.

This is why the exact wording of your prompt affects the format. The model isn’t analyzing your intent—it’s pattern-matching against training examples.

System Instructions Add Layer-Specific Rules

Beyond training data, each AI product has system-level instructions that shape responses. Claude’s Artifacts feature, for example, is designed to extract substantial code blocks into a separate, runnable pane. If you ask Claude to “write a Python script,” it’s more likely to use an Artifact than if you ask it to “show me how to reverse a string”—the first phrasing signals a complete, standalone piece of code.

ChatGPT has evolved similar behavior with Canvas, which presents code in an editable interface when the model detects you’re working on a multi-file project or substantial script. The system instructions tell the model to route certain types of coding requests to Canvas rather than inline code blocks.

Gemini’s interface doesn’t separate code the same way, but its system instructions emphasize different defaults: it tends to show shorter code snippets inline and use explanation-heavy responses for conceptual questions, likely because Google’s documentation style (which heavily influenced its training) favors that structure.

None of these decisions are visible to you. The model receives hidden instructions before it sees your prompt, and those instructions weight certain response formats over others.

Context Window Position Matters

If you’re several turns into a conversation, the model also considers what it already showed you. If it provided a code block three messages ago and you’re now asking a follow-up question, the model is more likely to reference that code inline (“Change line 7 to…”) rather than repeat the entire block with one modification.

This is efficient when it works, but frustrating when you actually want the full updated code and the model assumes you’ll patch it yourself. The model doesn’t know whether you saved the earlier code block or lost track of it—it just predicts the most common pattern from its training data, where follow-up answers tend to be incremental.

Long conversations also increase the chance the model will switch styles mid-thread. As the context window fills, earlier exchanges fade in relevance, and the model’s predictions rely more on recent messages. If your last few prompts were conceptual questions, a sudden request for code might still get an explanation-first response because the conversational momentum points that way.

How to Get the Format You Want

You don’t have to guess what format the model will choose. You can specify it directly in your prompt:

  • “Show me the complete code” — signals you want a full, copy-paste-ready block, not an explanation.
  • “Explain how this works without showing code” — gets you the concept in plain language.
  • “Give me the code first, then explain it” — sets the order explicitly.
  • “Write a Python script that…” — triggers features like Artifacts or Canvas that separate code into its own space.
  • “Show me just the line I need to change” — gets an inline snippet instead of a full rewrite.

If the model gives you the wrong format, you can correct it in a follow-up: “Show that as a complete code block” or “Explain that in plain English instead.” The model will usually comply, because your explicit instruction outweighs the patterns it inferred from your original question.

Why This Matters

Understanding these mechanics helps you avoid the friction of getting explanations when you need code, or code dumps when you’re trying to learn a concept. It also explains why the same question can get different responses depending on how you phrase it, which model you’re using, or where you are in a conversation.

The models aren’t reading your mind. They’re predicting the most statistically likely response format based on training data, system rules, and conversational context. The more clearly you signal what format you want, the less you’ll need to ask twice.

Want one useful AI idea in your inbox every day? Subscribe to the One Two Three AI newsletter and get practical tips like this—no fluff, just what works.

One Two Three AI — in your inbox

AI news, practical tips and how-to guides. One useful idea a day.

Other newsletters you might like

Love Netherlands

Canal towns, hidden villages, Dutch stories — a slow, loving look at the Netherlands, written by the people who love it most.

Subscribe

Irish Rugby Fans

The best Irish rugby updates, straight to your inbox — Six Nations, the Nations Championship and the provinces. Only when there's something worth reading.

Subscribe

Scottish Rugby Fans

The best Scottish rugby updates, straight to your inbox — Six Nations, the Nations Championship, Glasgow and Edinburgh. Only when there's something worth reading.

Subscribe

Love Space

Love Space — in your inbox. Space travel, rockets, planets and the cosmos. One cosmic idea a day.

Subscribe

Newsletters via the One Two Three Send network.  ·  Want your newsletter featured here? Click here

Scroll to Top