Tokens, context and output limits | Introduction to Generative AI
Understand how generative AI works, write source-bounded prompts, validate outputs, evaluate grounded answers and design a responsible career-learning assistant.
Prerequisites: No prior AI experience required. Basic familiarity with reading short code examples is helpful; no paid API account is needed.
Tokens, context and output limits
A language model typically consumes and produces tokens: units defined by its tokenizer. A token may be a word, part of a word, punctuation or another symbol. Token counts depend on the model and tokenizer, so splitting text on spaces does not give an exact token count. Character and word counts can still help you understand the size of an example, provided you label them accurately.
The context available to a request is limited. Instructions, supplied documents, conversation history and generated output all consume a budget according to the provider and model interface. If you send an entire long resume alongside many job descriptions, the request may exceed the available context or leave too little room for a useful answer. Choose relevant information first, reserve output space and use the provider tokenizer or usage measurements when integrating a real service.
An output limit does not guarantee that an answer is complete or useful. A short budget can truncate a JSON object or omit important conditions. Treat a model response as external data: check its shape, length and required fields. If the answer is incomplete, request a smaller task or use an explicit retry policy. Avoid assuming that raising the output limit makes a factual answer more reliable.
Worked example
text = "A candidate builds reliable Java services."
words = text.split()
print(len(words)) # A word count, not a tokenizer token count.
# In a real integration, use the selected provider tokenizer
# and record the returned input/output usage.
Try it yourself
Take a paragraph from your own writing. Count its characters and whitespace-separated words. Explain why neither count should be presented as an exact model-token measurement.
Check your understanding: explain why the example works, state one limitation, and record how you would test it.
Available response budget depends on: context limit − request tokens. Actual limits and accounting depend on the selected model/provider.
1. Understand generative AI
2. Give clear instructions
3. Ground and evaluate answers
4. Build a responsible learning prototype