Build Your First LLM App in Python

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.

What this course covers

  1. Your First Call to a Language Model: Send a message to a language model from a Python script, point the script at another provider by changing settings, and explain each part of the request and the response.
  2. Messages, Roles and the System Prompt: Write a system prompt that gives the model a job with rules, explain what each message role is for, and explain why the same request can return different text.
  3. Tokens, the Context Window and Cut-Off Replies: Read the token counts of a call, cap the length of a reply, detect a reply that was cut off, and work out what a call costs from its usage.
  4. Structured Output with Pydantic: Describe a wanted answer as a Pydantic model, request it as structured output, and receive a validated object in place of free text.
  5. Validate the Answer and Ask Again: Validate a structured answer on any endpoint, ask the model once more with the validation error when it does not fit, and return an explicit failure when it still does not.
  6. Tool Calling: Let the Model Look Up an Order: Define a tool, run the call the model asks for in your own code, send the result back, and trace every message of the exchange.
  7. Tool Calls You Can Rely On: Validate the arguments of a tool call before running it, report a failed call back to the model, answer several calls from one turn, and limit the rounds of the exchange.
  8. Errors, Timeouts and Retries: Sort the failures of a model call into retry or fix, set timeouts and retries on purpose, and end with a clear message when the model cannot be reached.
  9. Stream the Reply as It Is Written: Print a reply while the model is still writing it, assemble the full text from the chunks, and handle a stream that breaks in the middle.