Reorganize the requirements for better clarity and consistency. Improve documentation on scripts and workflows.
LangChain Documentation
For more information on contributing to our documentation, see the Documentation Contributing Guide.
Structure
The primary documentation is located in the docs/ directory. This directory contains
both the source files for the main documentation as well as the API reference doc
build process.
API Reference
API reference documentation is located in docs/api_reference/ and is generated from
the codebase using Sphinx.
The API reference have additional build steps that differ from the main documentation.
Deployment Process
Currently, the build process roughly follows these steps:
-
Using the
api_doc_build.ymlGitHub workflow, the API reference docs are built and copied to thelangchain-api-docs-htmlrepository. This workflow is triggered either (1) on a cron routine interval or (2) triggered manually.In short, the workflow extracts all
langchain-ai-org-owned repos defined inlangchain/libs/packages.yml, clones them locally (in the workflow runner's file system), and then builds the API reference RST files (usingcreate_api_rst.py). Following post-processing, the HTML files are pushed to thelangchain-api-docs-htmlrepository. -
After the HTML files are in the
langchain-api-docs-htmlrepository, they are not automatically published to the live docs site.The docs site is served by Vercel. The Vercel deployment process copies the HTML files from the
langchain-api-docs-htmlrepository and deploys them to the live site. Deployments are triggered on each new commit pushed tomaster.
Build Technical Details
The build process creates a virtual monorepo by syncing multiple repositories, then generates comprehensive API documentation:
-
Repository Sync Phase:
.github/scripts/prep_api_docs_build.py- Clones external partner repos and organizes them into thelibs/partners/structure to create a virtual monorepo for documentation building
-
RST Generation Phase:
docs/api_reference/create_api_rst.py- Main script that generates RST files from Python source code- Scans
libs/directories and extracts classes/functions from each module (usinginspect) - Creates
.rstfiles using specialized templates for different object types - Templates in
docs/api_reference/templates/(pydantic.rst,runnable_pydantic.rst, etc.)
- Scans
-
HTML Build Phase:
- Sphinx-based, uses
sphinx.ext.autodoc(auto-extracts docstrings from the codebase)docs/api_reference/conf.py(sphinx config) configuresautodocand other extensions
sphinx-buildprocesses the generated.rstfiles into HTML using autodocdocs/api_reference/scripts/custom_formatter.py- Post-processes the generated HTML- Copies
reference.htmltoindex.htmlto create the default landing page (artifact? might not need to do this - just put everyhing in index directly?)
- Sphinx-based, uses
-
Deployment:
.github/workflows/api_doc_build.yml- Workflow responsible for orchestrating the entire build and deployment process- Built HTML files are committed and pushed to the
langchain-api-docs-htmlrepository
Local Build
For local development and testing of API documentation, use the Makefile targets in the repository root:
# Full build
make api_docs_build
Like the CI process, this target:
- Installs the CLI package in editable mode
- Generates RST files for all packages using
create_api_rst.py - Builds HTML documentation with Sphinx
- Post-processes the HTML with
custom_formatter.py - Opens the built documentation (
reference.html) in your browser
Quick Preview:
make api_docs_quick_preview API_PKG=openai
- Generates RST files for only the specified package (default:
text-splitters) - Builds and post-processes HTML documentation
- Opens the preview in your browser
Both targets automatically clean previous builds and handle the complete build pipeline locally, mirroring the CI process but for faster iteration during development.
Documentation Standards
Docstring Format:
The API reference uses Google-style docstrings with reStructuredText markup. Sphinx processes these through the sphinx.ext.napoleon extension to generate documentation.
Required format:
def example_function(param1: str, param2: int = 5) -> bool:
"""Brief description of the function.
Longer description can go here. Use reStructuredText syntax for
rich formatting like **bold** and *italic*.
TODO: code: figure out what works?
Args:
param1: Description of the first parameter.
param2: Description of the second parameter with default value.
Returns:
Description of the return value.
Raises:
ValueError: When param1 is empty.
TypeError: When param2 is not an integer.
.. warning::
This function is experimental and may change.
.. deprecated:: 0.2.0
Use :func:`new_function` instead.
"""
Special Markers:
:private:in docstrings excludes members from documentation.. deprecated::creates deprecation notices.. warning::adds warning admonitions.. beta::(custom directive) marks beta features
Site Styling and Assets
Theme and Styling:
- Uses PyData Sphinx Theme (
pydata_sphinx_theme) - Custom CSS in
docs/api_reference/_static/css/custom.csswith LangChain-specific:- Color palette
- Inter font family
- Custom navbar height and sidebar formatting
- Deprecated/beta feature styling
Static Assets:
- Logos:
_static/wordmark-api.svg(light) and_static/wordmark-api-dark.svg(dark mode) - Favicon:
_static/img/brand/favicon.png - Custom CSS:
_static/css/custom.css
Post-Processing:
scripts/custom_formatter.pycleans up generated HTML:- Shortens TOC entries from
ClassName.method()tomethod()
- Shortens TOC entries from
Analytics and Integration:
- GitHub integration (source links, edit buttons)
- Example backlinking through custom
ExampleLinksDirective