Skip to content

shawnchoi8/langchain_basics

Repository files navigation

LangChain Basics

A hands-on study of LangChain core concepts.


What I Learned

1. Calling an LLM

Learned how to instantiate and invoke LLMs using LangChain's chat model wrappers.

  • ChatOllama — run local models via Ollama
  • ChatAnthropic — call Claude models via the Anthropic API

2. Prompts

Learned how to structure inputs to an LLM using prompt templates.

  • PromptTemplate — for simple string-based prompts with variables
  • ChatPromptTemplate — for multi-turn message-based prompts; supports variable substitution and LCEL chaining

3. Output Parsers

Learned how to parse and transform LLM responses into usable formats.

  • StrOutputParser — extracts the response content as a plain string
  • JsonOutputParser — parses the response as a JSON dict (requires the LLM to follow JSON format strictly)
  • with_structured_output(PydanticModel) — a more reliable approach using a Pydantic BaseModel to enforce structured output at the model level

4. Runnables & LCEL

Learned that PromptTemplate, LLMs, and Output Parsers all inherit from Runnable, meaning they all share a common .invoke() interface.

LangChain Expression Language (LCEL) allows these components to be connected with the | operator, forming a chain:

chain = prompt_template | llm | output_parser
chain.invoke({"country": "France"})

A chain itself is also a Runnable, so chains can be composed with other chains:

final_chain = {"country": country_chain} | capital_chain
final_chain.invoke({"continent": "Europe", "information": "..."})

Notebooks

File Topic
1. chat.ipynb LLM instantiation and basic invocation
2. prompt.ipynb PromptTemplate and ChatPromptTemplate
3. output_parser.ipynb StrOutputParser, JsonOutputParser, structured output with Pydantic
4. runnable.ipynb Runnables, LCEL, and chaining

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors