Before submitting large new features or refactors, please first discuss your ideas in the forum. This ensures alignment with project goals and prevents duplicate work.This does not apply to bugfixes or small improvements, which you can contribute directly via pull requests. Be sure to link any relevant issues in your PR description. Use to automatically close issues when the PR is merged.New integrations should follow the integration guidelines.
Philosophy
Aim to follow these core principles for all code contributions:Backwards compatibility
Maintain stable public interfaces and avoid breaking changes
Testing first
Every change must include comprehensive tests to verify correctness and prevent regressions
Code quality
Follow consistent style, documentation, and architecture patterns
Security focus
Prioritize secure coding practices and vulnerability prevention
Getting started
Quick fix: submit a bugfix
For simple bugfixes, you can get started immediately:2
Clone and setup
3
Create a branch
4
Make your changes
Fix the bug while following our code quality standards
5
Add tests
Include unit tests that fail without your fix. This allows us to verify the bug is resolved and prevents regressions
6
Run build
Run the build command to ensure the package still builds properly
7
Run tests
Ensure all tests pass locally before submitting your PR
8
Submit a pull request
Follow the PR template provided. If applicable, reference the issue you’re fixing using a closing keyword (e.g.
Fixes #123
).Full development setup
For ongoing development or larger contributions:1
Development environment
Set up your environment following our setup guide
2
Repository structure
Understand the repository structure and package organization
3
Development workflow
Learn our development workflow including testing, linting, and pre-commit hooks
4
Contribution guidelines
Review our contribution guidelines for features, bugfixes, and integrations
Development environment
Our JS/TS projects uses
pnpm
for dependency management. Make sure you have the latest version of pnpm
installed, or run corepack enable
(on Node 24+) to setup the required pnpm version.Core packages
Core packages
For changes to
langchain-core
:Main package
Main package
For changes to
langchain
:Provider packages
Provider packages
For changes to partner integrations:
Community packages
Community packages
For changes to community integrations:
Repository structure
LangChain is organized as a monorepo with multiple packages:
Core packages
Core packages
@langchain/core
(located inlibs/langchain-core/
): Base interfaces and core abstractionslangchain
(located inlibs/langchain/
): Main package with chains, agents, and retrieval logic
Partner packages
Partner packages
Located in
libs/providers/
, these are independently versioned packages for specific integrations. For example:@langchain/openai
: OpenAI integrations@langchain/anthropic
: Anthropic integrations@langchain/google-genai
: Google Generative AI integrations
Supporting packages
Supporting packages
@langchain/textsplitters
: Text splitting utilities@langchain/standard-tests
: Standard test suites for integrationslangchain-community
: Community maintained integrations
Development workflow
Testing requirements
Directories are relative to the package you’re working in.
1
Unit tests
Location:
src/tests/FILENAME_BEING_TESTED.test.ts
Requirements:- No network calls allowed
- Test all code paths including edge cases
- Use mocks for external dependencies
2
Integration tests
Integration tests require access to external services/ provider APIs (which can cost money) and therefore are not run by default.Not every code change will require an integration test, but keep in mind that we’ll require/ run integration tests separately as apart of our review process.Location:
src/tests/FILENAME_BEING_TESTED.int.test.ts
Requirements:- Test real integrations with external services
- Use environment variables for API keys
- Skip gracefully if credentials unavailable
3
Test quality checklist
- Tests fail when your code is broken
- Edge cases and error conditions are tested
- Proper use of fixtures and mocks
Code quality standards
Quality requirements:Required: Complete types for all functions
Contribution guidelines
Backwards compatibility
Breaking changes to public APIs are not allowed except for critical security fixes.See our versioning policy for details on major version releases.
Stable interfaces
Stable interfaces
Always preserve:
- Function signatures and parameter names
- Class interfaces and method names
- Return value structure and types
- Import paths for public APIs
Safe changes
Safe changes
Acceptable modifications:
- Adding new optional parameters/type parameters
- Adding new methods to classes
- Improving performance without changing behavior
- Adding new modules or functions
Before making changes
Before making changes
- Would this break existing user code?
- Check if your target is public
- Are there existing usage patterns in tests?
Bugfixes
For bugfix contributions:1
Reproduce the issue
Create a minimal test case that demonstrates the bug. Maintainers and other contributors should be able to run this test and see the failure without additional setup or modification
2
Write failing tests
Add unit tests that would fail without your fix
3
Implement the fix
Make the minimal change necessary to resolve the issue
4
Verify the fix
Ensure that tests pass and no regressions are introduced
5
Document the change
Update docstrings if behavior changes, add comments for complex logic
New features
We aim to keep the bar high for new features. We generally don’t accept new core abstractions, changes to infra, changes to dependencies, or new agents/chains from outside contributors without an existing issue that demonstrates an acute need for them. In general, feature contribution requirements include:1
Design discussion
Open an issue describing:
- The problem you’re solving
- Proposed API design
- Expected usage patterns
2
Implementation
- Follow existing code patterns
- Include comprehensive tests and documentation
- Consider security implications
3
Integration considerations
- How does this interact with existing features?
- Are there performance implications?
- Does this introduce new dependencies?
Security guidelines
Security is paramount. Never introduce vulnerabilities or unsafe patterns.
Input validation
Input validation
- Validate and sanitize all user inputs
- Properly escape data in templates and queries
-
Never use
eval()
, as this can lead to arbitrary code execution vulnerabilities
Error handling
Error handling
- Use specific exception types
- Don’t expose sensitive information in error messages
- Implement proper resource cleanup
Dependencies
Dependencies
- Avoid adding hard dependencies
- Keep optional dependencies minimal
- Review third-party packages for security issues
Testing and validation
Running tests locally
Before submitting your PR, ensure you have completed the following steps. Note that the requirements differ slightly between LangChain and LangGraph.1
Unit tests
2
Integration tests
3
Formatting
4
PR submission
Push your branch and open a pull request. Follow the provided form template. Note related issues using a closing keyword. After submitting, wait, and check to ensure the CI checks pass. If any checks fail, address the issues promptly - maintainers may close PRs that do not pass CI within a reasonable timeframe.
Test writing guidelines
In order to write effective tests, there’s a few good practices to follow:- Encapsulate the test in a
describe
block that describes the component being tested - Use natural language to describe the test name
- Be exhaustive with assertions
- Only use snapshots for reasonably sized data objects
Getting help
Our goal is to have the simplest developer setup possible. Should you experience any difficulty getting setup, please ask in the community slack or open a forum post.You’re now ready to contribute high-quality code to LangChain!