Stanford CS193T Thinking with AI | Autumn 2026 | Managing Sources
Summary
This lecture provides an advanced overview of managing the context window in Large Language Models (LLMs), moving beyond simple prompting. Key topics include the function of system prompts, automatic memory collection, and the implementation of Retrieval-Augmented Generation (RAG) to handle context overflow. A significant portion of the discussion focuses on the architectural vulnerabilities of LLMs, specifically prompt injection, and the importance of 'strategic withholding' to mitigate bias and security risks. The speaker emphasizes that the context window is a single, contiguous stream of tokens, and that external data sources (like web searches) introduce dangerous security risks.
Key takeaways
-
Context Window Composition
30:00
The context window is a single, contiguous stream of tokens that includes the system prompt, user prompts, model responses, uploaded documents, and web search results. Structurally, there are no clear, separate boundaries between these components, which is critical for understanding vulnerabilities. [~18:00]
-
Retrieval-Augmented Generation (RAG)
46:40
RAG is a solution for grounding LLMs when source material exceeds the context window capacity. It involves performing a search over a curated, external data store (the RAG data store) and selectively injecting only the most relevant document content into the context window. [~28:00]
-
Prompt Injection Vulnerability
53:20
Because the LLM cannot reliably distinguish between its own system instructions and external text (e.g., a web document), a malicious document can contain text that instructs the model to ignore previous safety guidelines and execute harmful actions (e.g., sending spam emails). This is a major security concern. [~32:00]
-
Strategic Withholding
To avoid bias or sycophancy, users should intentionally withhold information from the context window. For example, framing a request as evaluating a candidate's resume (rather than evaluating one's own) can elicit more candid, objective advice. [~45:00]
More digests on Context Window Management
Technical details
-
Context Window Management
90s
The context window is not limited to the immediate prompt/response pair; it accumulates all chat history, system preferences, uploaded files, and web search results. Tools like ChatGPT allow users to manage this via 'Personalization' settings, which essentially modify the system prompt. [~01:30]
-
System Prompts and Customization
130s
System prompts dictate the model's behavior (e.g., tone, formatting, level of challenge). Users can override or augment the default system prompt through platform settings (e.g., ChatGPT's personalization box or Claude's instructions). [~02:10]
-
Memory and Data Leakage
240s
Major AI tools automatically glean and remember information (e.g., location, job) from past chats, injecting this 'memory' into the context window of new sessions. Users must be aware of and control these memory collection settings. [~04:00]
-
Skills and Gems
330s
These features allow users to save complex, repeatable instructions (detailed scope of work prompts) within the tool itself, acting as reusable assets that function similarly to a persistent system prompt. Gemini calls these 'Gems,' while Claude uses 'Skills.' [~55:00]
Mentioned resources
- ChatGPT
- Claude
- Gemini
- Gemini Notebook (formerly Notebook LM)
Channel & topics
Watch on YouTube · Back to latest
This independent, AI-assisted summary is provided for commentary and informational purposes. It may contain errors or omit important context. Please watch the original video for the creator's complete presentation. Video, thumbnail, and related copyrights belong to their respective owners.