Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsHow toAsync APIDifferent call methodsCustom chainDebugging chainsLoading from LangChainHubAdding memory (state)Using OpenAI functionsSerializationFoundationalDocumentsMemoryAgentsCallbacksModulesSecurityGuidesMoreModulesChainsHow toCustom chainCustom chainTo implement your own custom chain you can subclass Chain and implement the following methods:from __future__ import annotationsfrom typing import Any, Dict, List, Optionalfrom pydantic import Extrafrom langchain.schema.language_model import BaseLanguageModelfrom langchain.callbacks.manager import (    AsyncCallbackManagerForChainRun,    CallbackManagerForChainRun,)from langchain.chains.base import Chainfrom langchain.prompts.base import BasePromptTemplateclass MyCustomChain(Chain):    """    An example of a custom chain.    """    prompt: BasePromptTemplate    """Prompt object to use."""    llm: BaseLanguageModel    output_key: str = "text"  #: :meta private:    class Config:        """Configuration for this pydantic object."""        extra = Extra.forbid        arbitrary_types_allowed = True    @property    def input_keys(self) -> List[str]:        """Will be whatever keys the prompt expects.        :meta private:        """        return self.prompt.input_variables    @property    def output_keys(self) -> List[str]:        """Will always return text key.        :meta private:        """        return [self.output_key]    def _call(        self,        inputs: Dict[str, Any],        run_manager: Optional[CallbackManagerForChainRun] = None,    ) -> Dict[str, str]:        # Your custom chain logic goes here        # This is just an example that mimics LLMChain        prompt_value = self.prompt.format_prompt(**inputs)
To implement your own custom chain you can subclass Chain and implement the following methods:
To implement your own custom chain you can subclass Chain and implement the following methods: ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsHow toAsync APIDifferent call methodsCustom chainDebugging chainsLoading from LangChainHubAdding memory (state)Using OpenAI functionsSerializationFoundationalDocumentsMemoryAgentsCallbacksModulesSecurityGuidesMoreModulesChainsHow toCustom chainCustom chainTo implement your own custom chain you can subclass Chain and implement the following methods:from __future__ import annotationsfrom typing import Any, Dict, List, Optionalfrom pydantic import Extrafrom langchain.schema.language_model import BaseLanguageModelfrom langchain.callbacks.manager import (    AsyncCallbackManagerForChainRun,    CallbackManagerForChainRun,)from langchain.chains.base import Chainfrom langchain.prompts.base import BasePromptTemplateclass MyCustomChain(Chain):    """    An example of a custom chain.    """    prompt: BasePromptTemplate    """Prompt object to use."""    llm: BaseLanguageModel    output_key: str = "text"  #: :meta private:    class Config:        """Configuration for this pydantic object."""        extra = Extra.forbid        arbitrary_types_allowed = True    @property    def input_keys(self) -> List[str]:        """Will be whatever keys the prompt expects.        :meta private:        """        return self.prompt.input_variables    @property    def output_keys(self) -> List[str]:        """Will always return text key.        :meta private:        """        return [self.output_key]    def _call(        self,        inputs: Dict[str, Any],        run_manager: Optional[CallbackManagerForChainRun] = None,    ) -> Dict[str, str]:        # Your custom chain logic goes here        # This is just an example that mimics LLMChain        prompt_value = self.prompt.format_prompt(**inputs)