Large Language Models (LLMs)

A large language model is a neural network trained on vast amounts of text to predict the next token, which — at scale — yields a system that can write, summarize, reason, translate, answer questions, and call tools. Modern frontier models like Anthropic's Claude (Opus 4.8, Sonnet 4.6, Haiku 4.5), along with others, power most of today's generative-AI applications.

You don't need to train one to use one well, but you do need the right mental model: an LLM is a probabilistic next-token predictor with a fixed knowledge cutoff and a bounded context window. Understanding tokens, context, sampling, and the model's failure modes (hallucination, staleness) is what separates reliable AI features from flaky ones.

TL;DR

Quick Example

Calling a frontier LLM is a single request — here, Claude via the Anthropic SDK:

Core Concepts

Tokens

Models don't see words — they see tokens (subword chunks). "tokenization" might be 3 tokens; a space or punctuation can be its own. Both your prompt and the model's output are measured in tokens, and you're billed per token. Rough rule: ~4 characters per token in English (more tokens for code and non-English text).

Context window

The context window is the maximum number of tokens the model can consider at once — prompt + output combined. Frontier models now offer very large windows (Claude's current models provide a 1M-token context). When you exceed it, you must trim, summarize, or compact earlier content.

The transformer

Today's LLMs are transformers, built on the attention mechanism that lets the model weigh relationships between all tokens in the sequence. Training predicts the next token over enormous corpora; later stages (instruction tuning, RLHF) align the model to follow instructions and be helpful and safe.

Sampling & temperature

Generation is probabilistic: at each step the model has a distribution over next tokens. Temperature (and top-p) control how much randomness is allowed — low values are more deterministic and focused, higher values more varied and creative. (Some frontier models now steer behavior through prompting rather than exposing these knobs.)

Capabilities & Limitations

Capabilities: drafting and editing text, summarization, classification, extraction, translation, code generation, reasoning over provided context, and — via tool use — taking actions in external systems.

Limitations to design around:

Choosing a Model

Match the model tier to the task — capability, latency, and cost:

💡 Start with a capable model to validate the task is even feasible, then consider a cheaper/faster tier once quality requirements are clear.

Best Practices

Common Mistakes

Trusting the model for current or precise facts

Ignoring the context window

FAQ

How is an LLM different from "AI" in general?

"AI" is the broad field; an LLM is one kind of AI model — a large transformer trained on text to predict tokens. LLMs are the engines behind generative-AI applications (chat, copilots, agents). Other AI includes computer-vision models, recommender systems, and classical ML. When people say "AI" today they often mean LLM-powered generative AI specifically, but the terms aren't synonymous.

Why do LLMs hallucinate, and how do I reduce it?

Because they generate the statistically likely next token, not verified facts — when they lack the information, they produce plausible-sounding text anyway. Reduce it by grounding the model in real data: retrieval-augmented generation (RAG), tool/function calling to fetch authoritative facts, asking for citations, instructing the model to say "I don't know," and validating critical outputs. You can lower the rate substantially but not eliminate it.

What's a token and why does it matter?

A token is the unit an LLM reads and generates — roughly a word-piece (~4 characters of English). It matters because context windows, latency, and pricing are all measured in tokens, for both input and output. Long prompts and long outputs cost more and can hit the context limit. Estimating token counts (with the provider's tokenizer/counting endpoint, not a different vendor's) helps you predict cost and stay within limits.

Do I need to fine-tune a model or train my own?

Almost never to start. Frontier models are highly capable out of the box, and you can adapt them with prompting, retrieval (RAG), and tool use — far cheaper and faster than training. Fine-tuning helps for narrow, high-volume tasks where you need specific behavior, lower latency, or a smaller model, and you have quality labeled data. Training from scratch is reserved for organizations with massive resources and specific needs.

Related Topics

References