Build Your First LLM App in Python
BeginnerCall a model, get answers your code can trust, give it tools and stream the reply.
You build
A command-line program that reads a customer support message, files it as a validated category, priority and summary, looks up the order it mentions, and streams a draft reply.
You need
- Python basics: functions, lists, dictionaries, handling errors and reading files (the course Python for AI from Zero is one way to get them). No experience with classes is needed: the few the course writes are explained as they appear.
- Running commands in a terminal
To build it on your own machine
This is optional and comes with a plan. The course pack brings the starting files, a ready container and a check for every lesson. You need only Docker and git, plus your own AI coding agent if you want a tutor.
What you learn
From a first model call to a program whose answers your code can rely on
You build one small program from the first lesson to the last: a support ticket helper for the command line. It reads a customer message, files it as a validated category, priority and summary, looks up the order the customer mentions, and streams a draft reply. Each lesson adds one working part, and every part runs on recorded answers too, so you can check your work without a key. You already write basic Python; you need no experience with language models.
- Talking to a Model. What a call to a language model really is: the request format most providers and local servers share, messages and their roles, the system prompt, tokens and the context window. You read every part of a response and know what it means.
- Answers Your Code Can Use. Free text is for people; code needs data. You describe the answer you want as a Pydantic model, receive it as a validated object, ask again when it does not fit, and learn what a schema guarantees and what it leaves to you.
- Tools. A model cannot know your orders, so it asks: it requests a function call, your code checks the arguments, runs the lookup and sends the result back, and the model answers from real data.
- Failures and Streams. Calls fail and replies take time. You tell the failures worth retrying from the ones to fix, set timeouts, and stream a reply to the screen as it is written.
Lessons
Your First Call to a Language Model
What an LLM API is, OpenAI-compatible endpoints, API keys as secrets, The request
Messages, Roles and the System Prompt
Message roles, The system prompt, A prompt as a specification, No memory between calls
Tokens, the Context Window and Cut-Off Replies
Tokens, The context window, Capping the reply, Cut-off replies
Structured Output with Pydantic
Why free text breaks code, Pydantic models, JSON Schema, Structured output
Validate the Answer and Ask Again
Enforced or only requested, Validation errors, Asking again with the error, Rules beyond the schema
Tool Calling: Let the Model Look Up an Order
What tool calling is, Tool definitions, The tool call, Returning the result
Tool Calls You Can Rely On
Validating arguments, Errors as results, Several calls in one turn, Repeating the exchange
Errors, Timeouts and Retries
Failure classes, Typed exceptions, Retry or fix, Rate limits
Stream the Reply as It Is Written
Why stream, Chunks and deltas, Assembling the reply, Tool calls in a stream
Where it fits
Course 1 of 3 on the AI Engineer path.