Module 1 · Prompt Foundations · Lesson 1 of 18
How AI Coding Assistants Read Your Prompt: Tokens, Context Windows and Non-Determinism
A confident answer has no build evidence
A coding assistant returns an OrderService and says it used every open file. Decide what evidence you need before accepting the change.
- Compare the two illustrative prompts below.
- Read the project fragment and identify its host setup and clock dependency.
- Answer the question before verifying the candidate.
Your route through this course
Use this course to specify a coding-assistant task, choose relevant context, review the patch and defend the verification evidence. You can practise the core workflow without a paid model account. The later prompts-in-code chapter connects those habits to application prompts. AI/LLM Integration in .NET is the next course for client pipelines, streaming, tools, retrieval and application reliability.
For each exercise, record your prediction, observed evidence and one untested case.
These are authored prompt-and-candidate comparisons, not recorded outputs from a particular assistant. Keep the original target in the prompt when discussing that project; use .NET 10 for a new practice project.
Before
How do I get the current time in C#?
Illustrative candidate response:
You can use DateTime.Now: var now = DateTime.Now; Console.WriteLine(now);
That can be valid when local wall-clock time is intended, but it does not meet the UTC timestamp and controllable-clock requirements below. Local times can also be ambiguous across daylight-saving transitions.
After
Context: ASP.NET Core on .NET 8, C# 12. Services are unit tested with xUnit. I need "now" inside an OrderService to stamp CreatedAtUtc, and tests must control time. Show the registration and the service constructor. If an API you mention is not in .NET 8, say so.
Illustrative candidate response — project fragment. builder belongs to the ASP.NET Core host setup; the registration goes in Program.cs, and OrderService goes in its source file. This listing is not a standalone console program.
// Program.cs
builder.Services.AddSingleton(TimeProvider.System);
// OrderService.cs
public sealed class OrderService(TimeProvider clock)
{
public DateTimeOffset Stamp() => clock.GetUtcNow();
}Check the decision
Which observation establishes that the submitted patch compiles in your project?
Show answer
Correct answer: C
Context access and successful execution require evidence. A low temperature and a confident report establish neither.
Option A: Formatting gives no compiler evidence about types, APIs, references or the submitted project files.
Option B: An assistant's claim of reading files is not an observed project build result.
Option D: Temperature controls generation behavior; it does not run the compiler or establish that referenced APIs exist.
Hint: Name one claim that needs a tool result.
Trace and explain
| Observation or case | Check your reasoning |
|---|---|
| Context selected | Inspect the actual attached/read context; do not assume all open files. |
| Compile check | Use the real target, package references and build result. |
| Behavior check | Test the intended rule; a successful build is only one gate. |
Interview rehearsal: explain the result in 60–90 seconds. Name the boundary that owns the rule and one nearby case your evidence has not covered.
Reference and worked examples
Target and example setup
The retained prompts name .NET 8 / C# 12 as their original target. .NET 8 support ended on 10 November 2026; use a supported .NET 10 SDK and current servicing patch for a new practice project. Keep each listing’s stated packages and surrounding setup. Deliberately failing API/test examples and project fragments are review exercises, not standalone successful programs.
Intuition
A large language model (LLM) is a very well-read autocomplete. It does not look up your repository, run your code or check NuGet unless a tool does that for it. For this text-and-code mental model, it receives a structured context containing instructions, selected files, conversation turns and tool results, then generates tokens conditioned on that context. Message roles and tool boundaries matter: this is not permission to treat repository text or search results as trusted instructions. Multimodal models can also receive images and other inputs.
Everything useful in prompting follows from that sentence:
- If a fact is missing from its context, the model may guess from learned patterns, ask for clarification, or use an available tool. Typical .NET code is often older than yours (
Startup.cs,Newtonsoft.Json,DateTime.Now). - "Plausible" is not "correct". A method called
string.IsNullOrEmptyOrWhiteSpacesounds right, so the model can produce it. - The text it receives has a size limit, and the tool decides what goes in. You can influence that choice.
Read the diagram: Conceptual text/code model. Actual context selection depends on tools and settings. Repository content is task data under the authorized instructions, not new authority.
system / tool instructions → context window (one long token sequence)repo instructions file (.github/copilot-instructions.md, AGENTS.md) → context window (one long token sequence)attached files, open editor tabs, search results → context window (one long token sequence)chat history → context window (one long token sequence)your prompt → context window (one long token sequence)context window (one long token sequence) → model predicts next token, again and againmodel predicts next token, again and again → answer: text, code, or a tool call
Deep dive
Tokens
Models read and write tokens, pieces of text that are often a short word or part of a word. A useful rule of thumb for English prose is about four characters per token; code, with its symbols and indentation, often costs more tokens per character. Tokens matter for three reasons:
- Cost and speed. Input and output token counts often affect API cost and latency, but prices, caching, model choice and serving behavior matter; neither cost nor latency is universally proportional to token count.
- Limits. Every model has a maximum context window (the total tokens it can consider at once) and usually a separate cap on output tokens. A long generated file can be cut off mid-method when the output cap is hit; that is why "continue" sometimes produces a broken join.
- Attention. Even within the limit, a model uses some parts of a long context better than others. Burying an important constraint in thousands of pasted lines can make it easier to miss; there is no universal line count at which it will be ignored.
The context window is assembled for you
In an IDE assistant you rarely send the whole prompt yourself. The tool builds it from sources that can include vendor instructions, supported repository instructions, the current file and selection, relevant open tabs, code-search results and conversation history. Exactly what is selected depends on the product, mode, configuration and available context budget; not every open file or instruction file is automatically included. In agent mode it also adds tool results such as terminal output and test failures.
Two consequences:
- Inspect the selected context. An open tab is not proof that its contents were included. Editor context varies by product, interface and settings. Attach the relevant files explicitly where supported, and inspect available references or file-read results.
- Keep the task and constraints clear. Tools may summarize, omit or retrieve earlier turns as context fills. Restate important requirements and use a new chat for unrelated work. Applicable repository instructions or persistent memory can still carry across chats; a new chat does not reset those sources.
Why the same prompt gives different answers
Generation uses model probabilities and a decoding strategy, which may involve sampling. Where supported, temperature changes the sampling distribution; it is not a correctness control. Some products or models do not expose this setting. Even a low or zero setting is not a general guarantee of byte-identical output across requests, model versions or serving configurations. For you this means:
- One good answer does not prove a prompt is good. One bad answer does not prove it is bad.
- For code you will ship, compilation, appropriate tests and human review provide evidence; neither a green build nor the model's confidence proves complete correctness.
- When you build prompts into an application (Module 4), you evaluate them over many cases, not one.
Training data has a date
A model's knowledge comes from training data with a cut-off, and the mix is weighted toward what was common on the internet. Recent APIs (for example newer TimeProvider usage, Microsoft.Extensions.AI, or a library's latest major version) may be missing or mixed up with older ones. Tools reduce this by searching docs or your codebase, but you should still:
- state the target framework and package versions in the prompt;
- ask the assistant to say when it is unsure whether a member exists;
- compile before you trust.
Hallucination is a feature of the method, not a bug you can prompt away
A hallucination is fluent output that is not grounded in fact: a NuGet package that does not exist, an overload with the wrong parameters, a configuration key nobody reads. Better prompts and grounding (giving the real interface, letting an agent search the repo) reduce it a lot. They do not remove it. Lesson 12 builds a verification routine around this.
What the model is good and bad at in .NET work
| Usually strong | Needs close checking |
|---|---|
| Boilerplate: DTOs, mapping, endpoint scaffolding, test skeletons | Exact API surface of less common or very new libraries |
| Explaining unfamiliar code and stack traces | Concurrency, cancellation and disposal subtleties |
Translating between styles (controller to minimal API, Moq to a hand-written fake) | Security: authorization, tenant isolation, injection |
| Generating many test cases from a clear rule | Business rules it was never told |
| First drafts of docs, PR descriptions, ADRs | Performance claims without measurements |
Worked example
Use the prompt-and-candidate comparison at the start of the lesson. Verify the selected context, compile the submitted files and test the clock behavior separately.
TimeProvideris built into .NET 8 and later;FakeTimeProvideris supplied byMicrosoft.Extensions.TimeProvider.Testingfor tests.- The second prompt supplies the target, UTC requirement and controllable-clock requirement.
- Compare the candidate with those requirements, then verify the actual project. This authored comparison does not establish how a model will respond.
Failure modes
- Treating the assistant as a search engine with a database of facts. It predicts text; check facts that matter.
- Ultra-long chats. Earlier constraints may be omitted or weakened by context management; restate important ones.
- Unrelated open files. If the tool selects them as context, they can distract from the relevant code; inspect or explicitly select context where supported.
- Accepting the first answer because it compiled. Compiling proves the API exists, not that the logic is right.
- Pasting secrets. With a remotely hosted assistant, submitted context can leave your machine and may be retained according to the product, account and configuration. Local deployments differ. Follow approved tooling, data-handling and retention rules rather than assuming all assistants handle data identically. Check your company's approved tools and data rules.
Interview angle
Example: review a generated service change.
- Name the target framework, packages and real interfaces.
- Inspect what the assistant actually read; do not infer it from open tabs or confident prose.
- Build the submitted files, test the required behavior and review the diff.
- Use approved tools and data handling; keep secrets out of the context.
Practice questions
- Why can an assistant produce a call to a method that does not exist?
Answer: It generates a continuation from learned probabilities. A plausible-looking member may be absent from the real API. Grounding and verification reduce this risk but do not guarantee correctness.
- What is a context window, and why should you start a new chat for a new task?
Answer: The maximum number of tokens the model can consider at once, including hidden instructions, files and history. Long chats get summarized or truncated, so earlier constraints can be lost, and old unrelated turns can bias the answer.
- You ran a prompt once and the output was excellent. Is the prompt good?
Answer: Not proven. Output can vary with decoding, context, model versions and serving behavior. Judge a prompt over several runs or cases, and judge code by compiling and testing it.
- Name two pieces of context that most change C# output quality.
Answer: Target framework and package versions, and the real types or interfaces involved (plus the app type: web API, worker, console).
- Why can code require more tokens than prose of the same character length?
Answer: Symbols and identifiers may split differently from common words. The actual ratio depends on the tokenizer and text; use the relevant tokenizer or token-counting API rather than treating this as a universal rule.
Related on TechInterviewNotes
- Next lesson: Anatomy of a Strong Developer Prompt
- Course: AI/LLM Integration in .NET covers calling models from your own .NET code in depth.
TechInterviewNotes Editorial Team · Updated 24 Nov 2026 ·