Lesson 8 of 11
Chapter 18 . LangGraph . Lesson 8 of 11

An LLM inside a node

A node can call an LLM. Its structured answer decides which edge the graph takes next.

01Real-world example

Illustration: AI-assisted triage: read a failure log, classify it as a product bug, test bug, environment issue or flake, and route it to the right team.
AI-assisted triage: read a failure log, classify it as a product bug, test bug, environment issue or flake, and route it to the right team.

02The graph

An LLM inside a node as a graph
classify asks the LLM for one of four labels. route() sends the test on its way.

03How the code does it

  • with_structured_output(Triage) forces the answer into the Pydantic shape: category must be one of four literals.
  • route() only reads triage.category: the model decides, plain Python routes, and the graph stays in control.
  • make_action(cat) builds one node per category in a loop, so adding a category is one dict entry.
  • get_llm() stops with a clear message when GROQ_API_KEY is missing.

Key points

  • with_structured_output gives a fixed answer shape
  • The model picks. The router routes.
  • Needs GROQ_API_KEY in .env

04Run it

terminal
cd chapter_18_LangGraph/src/chapters
python 008_LLM_Node.py
output
checkout_pay    -> product_bug  | file a Jira bug for the dev team
login_button    -> test_bug     | fix the test code (locator / assertion)
search_results  -> environment  | ping DevOps, rerun when the env is healthy
The model also prints a one-line reason for each. Its wording changes run to run.
Needs a key. Copy chapter_18_LangGraph/.env.sample to .env and add a free Groq key from console.groq.com.