liveBook · Manning

Context window

As explained in Learn AI Data Engineering

A context window is the finite amount of text or tokens that a language model can process in one interaction.

A context window is the finite amount of text or tokens a language model can process in one interaction. Prompts, code, schemas, table definitions, and instructions all consume that capacity. When the limit is reached, earlier information may be truncated or ignored, causing incomplete reasoning, missing references, or invented functions. section 2.3

For data-engineering work, the practical risk is incomplete schema awareness. An LLM cannot see an entire codebase, business logic, naming system, or data lineage unless those details are supplied. Large schemas and long multi-step prompts can therefore produce SQL that is inaccurate, incomplete, or based on generic assumptions. section 2.3 section 3.1

Manage context-window constraints with a deliberate prompt-and-validation workflow:

  • Keep prompts concise and include only the schema details, constraints, and examples needed for the immediate task. section 3.1
  • Provide schema documentation, DDL, ERD diagrams, or table excerpts when the model does not already know the data structure. section 2.3 section 3.1
  • Reset the conversation when earlier requirements disappear or the model begins drifting or hallucinating. section 3.1
  • Run generated SQL in a database client and inspect the results rather than treating the response as automatically correct. section 3.1

Testing a Pagila SQL prompt

Ask for the five most-rented films using the Pagila dataset, copy the generated SQL into pgAdmin, and check the results. The familiar schema fits within one context window, but a modified or custom schema requires explicit schema context. If the model loses table relationships or constraints, shorten the prompt, add schema excerpts, or restart the conversation. section 2.3 section 3.1

SELECT f.title, COUNT(*) AS rental_count
FROM rental r
JOIN inventory i ON r.inventory_id = i.inventory_id
JOIN film f ON i.film_id = f.film_id
GROUP BY f.title
ORDER BY rental_count DESC
LIMIT 5;

Use the Pagila query as a concrete artifact for checking whether the model retained the required joins, grouping, ordering, and row limit. section 3.1

How Learn AI Data Engineering covers it

How deep it goes
Defines token capacity, explains truncation failures, and gives prompt, schema, reset, and validation practices.
Examples
Uses Pagila schemas, top-five rental queries, schema excerpts, and pgAdmin result checks.
What it assumes
Assumes familiarity with SQL prompts and schemas while defining context windows and their failure modes directly.
What you can do after
Diagnose SQL prompt failures by checking context loss, supplying schema evidence, resetting conversations, and testing generated queries.
How it connects
Connects context windows with large language models, schema drift, prompt engineering, SQL generation, and hallucination.

Also explained in

Compare how 38 books explain context window →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI Data Engineering. The section links point to the parts of the book it draws on.