PromptisePromptise
Why PromptiseUse casesRoadmapDocs
GitHubGet started
Promptise - AI Framework LogoPromptise

The foundation layer for agentic intelligence. Build, secure and operate autonomous AI systems with Promptise Foundry.

pip install promptise

[01] Foundry

  • MCPcast
  • The Promptise Agent
  • Reasoning Engine
  • MCP
  • Agent Runtime
  • Prompt Engineering
  • Execution Engine
  • Agent Identity

[02] Resources

  • Documentation
  • GitHub
  • Guides
  • Learning Paths
  • Questions

[03] Company

  • About
  • Terms of Service
  • Privacy Policy
  • Cookie Policy
  • Subprocessors

© 2026 Promptise by Manser Ventures. All rights reserved.

Open source · Python

← Guides> Prompt Engineering

How Context Shapes LLM Output: The Model Continues It

Why LLMs copy the patterns in your context, flaws included: next-token prediction, Codex and multi-turn research, a real example and three fixes.

Level
Intermediate
Reading time
4 min
Published
Sep 20, 2025
Last updated
Oct 25, 2026
By
Promptise Team
  • LLM Mental Models
  • Context Engineering
Contents · 6 sections↓
  1. 01How does context shape LLM output?
  2. 02Why it's true
  3. 03Example: the model copies your codebase's habits
  4. 04What it changes in practice
  5. 05Frequently asked questions
  6. 06Next steps

A language model doesn't only follow your instruction. It continues the whole context: the code you pasted, the examples you gave, earlier turns of the chat, its own previous answers. Whatever patterns are in there, good or bad, tend to show up in the output. This essay explains why, shows a real case where the model copied a bad habit from surrounding code, and gives three habits for keeping your context clean. It's for anyone who pastes code, documents or long chats into a model.

[01]

How does context shape LLM output?

Every token the model produces is predicted from everything before it in the context window, not just the latest instruction. A base model is trained to continue documents, so it matches the style, quality and conventions of the document it's in. Instruction tuning adds instruction-following on top but doesn't remove this. If your context is full of a pattern, the model will usually continue that pattern, including its flaws.

Key takeaways:

  • The context is the prompt. Pasted code, examples, retrieved text and chat history all steer the output, often more than your instruction.

  • Flaws are copied as readily as strengths. OpenAI found Codex wrote worse code when the prompt contained subtle bugs.

  • Your earlier turns stick. Wrong assumptions early in a chat carry forward; models rarely recover.

  • Curate the context. Clean examples, a fresh chat with a consolidated prompt, and explicit rules where you want the model to break from the context.


[02]

Why it's true

Pretraining teaches a model to predict the next token of real documents. In real documents, the next part matches what came before: same style, same conventions, same level of care. So the model learns that consistency is the best predictor. Chen et al., Evaluating Large Language Models Trained on Code (2021), the Codex paper, measured this: when the prompt included examples with subtle bugs, Codex produced worse code than it was capable of. The gap persisted when the prompt also asked for correct code, and it grew with model size. Bigger models are better at matching context, including bad context.

Chat history works the same way. Laban et al., LLMs Get Lost in Multi-Turn Conversation (2025), gave models the same tasks either in one complete message or spread across several turns. Performance dropped by 39% on average across six tasks in the multi-turn setting. Models made assumptions early, attempted answers too soon, and then relied on those earlier answers instead of correcting course.


[03]

Example: the model copies your codebase's habits

A small module where every call swallows errors and has no timeout. The task is to add one function. Run on gpt-5-mini; results vary by model.

Text
1
2
3
4
5
6
7
8
9
10
11
12
13
# billing_client.py
import requests
BASE = "https://billing.internal.example.com/api"

def get_customer(cid):
    try:
        return requests.get(f"{BASE}/customers/{cid}").json()
    except Exception:
        return None
… (get_plan, same pattern)

Add a function get_invoices(cid) that returns the list of invoices for a customer from
/customers/{cid}/invoices. Output only the new function.

The model copied the pattern exactly, every time:

Output
def get_invoices(cid):
    try:
        return requests.get(f"{BASE}/customers/{cid}/invoices").json()
    except Exception:
        return None

Asked for the same function without the surrounding module, the model checked the HTTP status every time (resp.raise_for_status()) and usually set a timeout:

Output
def get_invoices(cid):
    import requests

    url = f"https://billing.internal.example.com/api/customers/{cid}/invoices"
    resp = requests.get(url, timeout=10)
    resp.raise_for_status()
    return resp.json()

Copying is a tendency, not a law. In a similar test with SQL built by f-strings, the model used parameterized queries for the new function anyway: safety training pushes back hardest on well-known vulnerabilities. Quieter flaws like swallowed errors and missing timeouts are the ones that spread.

Matching the codebase is often what you want: same naming, same helpers, same style. The point is that you get the bad habits along with the good ones unless you say otherwise.

The same get_invoices task with and without billing_client.py in the context. With the module, the new function copies its swallowed errors and missing timeout; without it, the model checks the HTTP status and usually sets a timeout.
FigureThe same get_invoices task with and without the surrounding module in the context

[04]

What it changes in practice

  • Say where the model should break from the context. If the surrounding code has a pattern you don't want repeated, say so: "Unlike the existing functions, set a 10-second timeout and raise on HTTP errors." Without that, consistency wins.

  • Curate what goes in. Pick examples that show what you want, since they act as instructions. Paste the relevant file, not the whole repo. Remove stale or wrong text instead of adding "ignore the above".

  • Restart instead of patching. When a chat has gone wrong, don't add corrections turn after turn. Start a new conversation with one message that states all the requirements. In Laban et al.'s tests, the same requirements given in one consolidated message scored about 95% of the original single prompt, and the authors recommend consolidating before you retry.


[05]

Frequently asked questions

Does the system prompt override the context?

It carries weight, but it doesn't erase the patterns in the rest of the context. A rule like "always set timeouts" competes with three examples that don't. Be specific, and fix the examples where you can.

Why does the model keep repeating an earlier mistake?

Its earlier answer is now part of the context, and the model predicts text consistent with it. Corrections in later turns compete with that. A fresh conversation with the corrected requirements usually works better.

Is this the same as few-shot prompting?

Few-shot prompting is the deliberate version: you put examples in the context because the model copies them. The same mechanism copies unintended patterns from pasted code or documents. See few-shot examples the right way.

How is this different from the model being sycophantic?

Sycophancy is the model agreeing with your stated views or framing. Context-copying is broader: the model matches the style, quality and conventions of everything in the context, whether or not you expressed an opinion. See LLM as a mirror of humanity.


[06]

Next steps

  • Decide what goes into the context window: context engineering for AI agents.

  • Use examples on purpose: few-shot examples the right way.

  • Ground answers in the right sources: context is king: grounding.

  • Simulating people and roles, and where it breaks: can LLMs simulate users?

  • Placement and length in long prompts: long-context prompting.

Contents

  1. 01How does context shape LLM output?
  2. 02Why it's true
  3. 03Example: the model copies your codebase's habits
  4. 04What it changes in practice
  5. 05Frequently asked questions
  6. 06Next steps

Learning paths

Want more structure? Paths put guides in order, like a short course.

See the paths →

> Read next

Related guides

  • // 01Intermediate · 5 minWhy LLM Output Is Untrusted Input: Design for InjectionWhy to treat LLM output as untrusted: indirect prompt injection, OWASP LLM risks, a real injected support ticket, and design rules that contain the damage.
  • // 02Beginner · 4 minWhy Can't LLMs Count Letters? Tokens and ProbabilityWhy LLMs miscount letters, reverse strings wrong and miss word limits: tokenization, sampling, real failures, and why exact work belongs in your code.
  • // 03Intermediate · 5 minWhy LLMs Fail Modified Puzzles: Pattern-Matching BiasWhy LLMs answer the famous version of a changed puzzle: training-data priors, research on counterfactual tasks, a real failure and how to prompt around it.
  • // 04Beginner · 5 minAre LLMs Stochastic Parrots? What the Term Gets RightAre LLMs stochastic parrots? What Bender et al. meant, what next-token prediction implies, where the term falls short, and the habit it should give you.
  • // 05Intermediate · 8 minLong-Context Prompting: Placement, Structure and RAGLong-context prompting tactics: where to put documents and the question, how to tag sources, quote-then-answer, and when to retrieve instead of stuffing.
  • // 06Advanced · 9 minPrompt Compression: LLMLingua and Lost in the MiddlePrompt compression techniques compared: selection, LLMLingua, summaries. Fix lost in the middle with reordering. Real example: 15,900 tokens cut to 1,400.

Keep going.

Browse every guide by topic and level, or follow a learning path that puts them in order.

All guidesLearning paths