AI Hints
Home›LangGraph Tutorial›Parallel Branches and Schemas
LangGraph · Lesson 23 of 120

Input and Output Schemas

Public and private.

⏱ 2 min read▶ Video at 24:07🎓 Free
Watch this lesson in the LangGraph courseWatch on YouTube ↗Full LangGraph course

Inside a graph, the state often holds working data, like intermediate prices, or flags. Callers don't need to see all that. Input and output schemas say what goes in, and what comes out.

Input and Output Schemas
From the video: Input and Output Schemas
  • Working data inside
  • Callers need less
  • Define what's in and out

A clean interface

The full state has the title, a working price, and a reply. The input schema accepts only the title. The output schema returns only the reply. We pass them to state graph. Run it. We send just a title, and get back just the reply. The working price stays private.

schemas.pypython
from typing import TypedDict
from langgraph.graph import StateGraph, START, END

class In(TypedDict):
    title: str
class Out(TypedDict):
    reply: str
class State(In, Out):
    price: float

def look_up(s): return {"price": {"Dune": 9.99}.get(s["title"], 0.0)}
def answer(s):  return {"reply": f"{s['title']} costs £{s['price']}"}

b = StateGraph(State, input_schema=In, output_schema=Out)
b.add_sequence([look_up, answer]); b.add_edge(START, "look_up"); b.add_edge("answer", END)
print(b.compile().invoke({"title": "Dune"}))
Output
{'reply': 'Dune costs £9.99'}

Why schemas help

Schemas make a graph easy to use, like a function with clear arguments and a clear return value. They keep private data private. And they matter later, when one graph is used inside another, as a subgraph.

keyvalue
Input schemawhat callers send
Output schemawhat they get
Privateworking keys hidden
Latersubgraphs

Summary

Input and output schemas define a graph's public interface, and hide its working data. Next, a quiz on branching.

Key takeaways
  • input_schema
  • output_schema
  • Private working keys
Next up: Branching Quiz — test yourself