Why this matters
Before you bolt an AI feature onto your Django project, it helps to know what AI actually is — and when traditional code beats it. This primer cuts through the hype and gives you a working mental model.
AI, machine learning, and LLMs — what's the difference?
These three terms get used interchangeably, but they're not the same:
- AI (Artificial Intelligence) is the broad field — anything where software does something that "looks intelligent." A chess engine is AI. A spam filter is AI. ChatGPT is AI.
- Machine learning (ML) is a subset of AI where the system learns patterns from data instead of being explicitly programmed. Recommendation engines, fraud detection, image classification — all ML.
- Large language models (LLMs) are a specific type of ML model trained on enormous amounts of text. Claude, GPT, Gemini, Llama — these are LLMs. They're great at language tasks: writing, summarizing, classifying, extracting information, answering questions.
When someone says "let's add AI to our app" today, they almost always mean an LLM. That's the focus of this series.
When to use AI vs traditional code
The single best decision framework: if you can write a deterministic rule for the problem in 10 lines of Python, do that. AI is for problems where rules are hard to write or maintain.
Good fits for LLMs in a Django app:
- Summarizing long content — turn a 5000-word article into a 200-word abstract
- Extracting structured data from messy input — pulling fields out of an email or PDF
- Natural-language search — "show me orders from last week over €100" → SQL
- Customer support triage — categorize incoming tickets, draft replies
- Content moderation — flag spam, abuse, off-topic posts
- Answering questions over your own documentation — RAG (covered in tutorial 5)
Bad fits for LLMs:
- Math — LLMs are notoriously bad at arithmetic. Use Python.
- Lookups in a database — just query the database.
- Anything where wrong answers cost real money or harm users without a human review step.
- High-throughput, latency-sensitive operations — LLMs are slow (hundreds of milliseconds to many seconds per call).
The mental model
Think of an LLM as a junior employee with a very wide but shallow knowledge base, no memory between conversations, and a tendency to confidently make things up. You wouldn't hand them your customer database and ask for an audit. But you might ask them to draft an email, summarize a meeting, or classify some support tickets — with you reviewing the output.
In Django terms:
# Bad: Trust the LLM to compute pricing
result = llm("What is the total of items 1, 2, 3 with 21% VAT?") # Often wrong
# Good: Use the LLM for the part it's good at, Python for the rest
items = Cart.objects.filter(...)
total = sum(item.price for item in items) * Decimal("1.21")
description = llm(f"Write a friendly receipt summary for: {items}")
Cost and latency reality
- API calls cost money. Claude Sonnet 4.6 is around $3 per million input tokens. A typical request might cost $0.001 to $0.05. That's nothing for a single user, painful at a million users.
- Each call takes 0.5–10 seconds, sometimes more. You must stream long responses (covered in tutorial 8) — users will not wait staring at a spinner.
- You will hit rate limits in production. Plan retries with exponential backoff and circuit breakers.
A 30-second decision framework
Before you reach for an LLM, ask:
- Is this a language task? (writing, classifying, extracting, answering) — LLM might fit.
- Can a deterministic rule do it? — Use the rule.
- What's the cost of wrong output? — High → require human review.
- What's the latency budget? — < 200ms → LLM is too slow without caching.
- What's the volume? — High → cost matters, pick a smaller/cheaper model.
If you got "yes, language task, no deterministic rule, low cost of wrong output, latency budget OK" — go ahead and integrate.
What's next
The next tutorials in this series go deeper:
- How LLMs actually generate text (you don't need to be a researcher, but the basics matter)
- Reasoning models and when extended thinking is worth the cost
- Calling Claude from Django, with proper streaming and error handling
- Building RAG so your LLM can answer questions about your data
- Cost optimization, prompt patterns, and the full PoC-to-production roadmap
Each tutorial assumes you've read this one — so the mental model carries through.