LLM (Large Language Model)
A stateless next-token prediction engine that turns natural-language prompts into text, code, or structured decisions.
What It Is
An LLM is a transformer-based neural network trained on vast amounts of text, documentation, and source code to predict the most likely next token given all preceding tokens. Crucially for software engineers, an LLM API has no built-in memory between calls: every request is completely stateless, meaning your application must send the system rules, relevant history, and facts on every single call.
Think of an LLM as a stateless probabilistic CPU: instead of executing deterministic x86 instructions, it executes natural-language instructions and returns the most probable completion.
How It Works (Step-by-Step)
- 01Your app sends a prompt string (system instructions + conversation history + user message) over HTTPS.
- 02A tokenizer converts that text into integer token IDs.
- 03Transformer attention layers compute probabilities for what token should come next.
- 04The model emits one token at a time (streaming) until it hits a stop token or max output limit, then forgets everything.
Real-World Scenario
In a customer support tool, the model doesn't magically remember message #1 when the user sends message #2—your backend loads `[message_1, assistant_reply_1, message_2]` from Postgres/Redis and passes the whole array to the LLM.
When to Use vs. When NOT to Use
Use for summarizing unstructured text, classifying intent, translating formats, drafting code, and reasoning over ambiguous inputs.
Do not use for exact arithmetic, deterministic CRUD queries, strict business accounting, or tasks solvable in 5 lines of standard code.
Common Beginner Mistakes
- Assuming the model 'remembers' previous API calls automatically without re-sending conversation state.
- Asking an LLM to perform exact multi-digit math or live database lookups without giving it a code/calculator tool.
- Treating LLM outputs like deterministic SQL results instead of validating format and edge cases.
Code Example
from google import genai
from google.genai import types
client = genai.Client()
# Because LLMs are stateless, your app manages and sends the conversation history.
conversation = [
types.Content(role="user", parts=[types.Part.from_text(text="We use PostgreSQL 16.")]),
types.Content(role="model", parts=[types.Part.from_text(text="Got it—PostgreSQL 16 noted.")]),
types.Content(role="user", parts=[types.Part.from_text(text="How do I add a vector column?")]),
]
response = client.models.generate_content(
model="gemini-2.5-flash",
contents=conversation,
config=types.GenerateContentConfig(
system_instruction="Be concise and provide runnable SQL examples.",
temperature=0.2,
),
)
print(response.text)