Langchain Decorators logo

Langchain Decorators

Free

a layer on the top of LangChain that provides syntactic sugar 🍭 for writing custom langchain prompts and chains ![GitHub Repo stars](https://img.shields.io/github/stars/ju-bezdek/langchain-decorators?style=social)

FreeFree tier
Type
Open Source

About Langchain Decorators

LangChain Decorators is a lightweight, unofficial layer built on top of LangChain that provides syntactic sugar for writing custom prompts and chains. It offers a more Pythonic way to define prompts using functions and docstrings, with full IDE support for type hints and parameter documentation. The library supports multi-line prompts without indentation issues, optional parameters, chat message roles, output parsers, session management, tool calling, enum arguments, streaming, structured output, and easy parameter sharing by binding prompts to a class. It maintains full compatibility with the LangChain ecosystem.

Key Features

Pythonic prompt writing using function decorators and docstrings
Multi-line prompts without breaking code indentation
IDE support with type hints, parameter documentation, and doc popups
Support for optional parameters and default values
Chat message roles via special code blocks in docstrings
Binding prompts to a class to easily share parameters
Output parsers for structured responses
Chat sessions and thread management
Tool calling and enum arguments
Simplified streaming and structured output

Pros & Cons

Pros
  • More Pythonic and concise than raw LangChain prompt templates
  • Full IDE support improves developer experience and reduces errors
  • Supports optional parameters, making prompts flexible and reusable
  • Easy to document prompts directly in the function docstring
  • Maintains full compatibility with the LangChain ecosystem and tools
Cons
  • Unofficial add-on, not maintained or endorsed by the LangChain team
  • Opinionated design may not fit every workflow or preference
  • Smaller community and less documentation compared to LangChain itself
  • Potential compatibility issues with future LangChain updates

Best For

Writing custom LangChain prompts and chains with less boilerplateCreating chat prompts with multiple message roles (system, user, assistant)Building complex LLM applications with a Pythonic, intuitive syntaxSharing common parameters across multiple prompts by class bindingRapid prototyping and experimentation with LangChain

FAQ

What is LangChain Decorators?
It is a lightweight, unofficial layer on top of LangChain that provides syntactic sugar for writing custom prompts and chains using Python function decorators and docstrings.
How do I install LangChain Decorators?
Install via pip: `pip install langchain_decorators`
How do I define a prompt with LangChain Decorators?
Define a function decorated with @llm_prompt. The function arguments become the prompt inputs, and the docstring becomes the prompt template. For chat messages, use code blocks with a role tag (e.g., prompt:system).
What are the main benefits of using LangChain Decorators?
It offers a more Pythonic syntax, IDE support (type hints, doc popups), optional parameters, multi-line prompts without indentation issues, and easy sharing of parameters between prompts by binding them to a class.