LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • MCP Adapters
    • Overview
    • Agents
    • Callbacks
    • Chains
    • Chat models
    • Embeddings
    • Evaluation
    • Globals
    • Hub
    • Memory
    • Output parsers
    • Retrievers
    • Runnables
    • LangSmith
    • Storage
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    MCP Adapters
    OverviewAgentsCallbacksChainsChat modelsEmbeddingsEvaluationGlobalsHubMemoryOutput parsersRetrieversRunnablesLangSmithStorage
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-classicchainsqa_generationbaseQAGenerationChain
    Class●Since v1.0Deprecated

    QAGenerationChain

    Copy
    QAGenerationChain()

    Bases

    Chain

    Attributes

    Methods

    Inherited fromChain

    Attributes

    Amemory: BaseMemory | None
    —

    Optional memory object.

    Acallbacks: CallbacksAverbose: boolAtags
    View source on GitHub
    : list[str] | None
    Ametadata: dict[str, Any] | None
    Acallback_manager: BaseCallbackManager | None
    —

    [DEPRECATED] Use callbacks instead.

    Amodel_config

    Methods

    Mget_input_schemaMget_output_schemaMinvokeMainvokeMraise_callback_manager_deprecation
    —

    Raise deprecation warning if callback_manager is used.

    Mset_verbose
    —

    Set the chain verbosity.

    Macall
    —

    Asynchronously execute the chain.

    Mprep_outputs
    —

    Validate and prepare chain outputs, and save info about this run to memory.

    Maprep_outputs
    —

    Validate and prepare chain outputs, and save info about this run to memory.

    Mprep_inputs
    —

    Prepare chain inputs, including adding inputs from memory.

    Maprep_inputs
    —

    Prepare chain inputs, including adding inputs from memory.

    Mrun
    —

    Convenience method for executing chain.

    Marun
    —

    Convenience method for executing chain.

    Mdict
    —

    Return dictionary representation of agent.

    Msave
    —

    Save the agent.

    Mapply
    —

    Utilize the LLM generate method for speed gains.

    Inherited fromRunnableSerializable(langchain_core)

    Attributes

    AnameAmodel_config

    Methods

    Mto_jsonMconfigurable_fieldsMconfigurable_alternatives

    Inherited fromSerializable(langchain_core)

    Attributes

    Alc_secretsAlc_attributesAmodel_config

    Methods

    Mis_lc_serializableMget_lc_namespaceMlc_idMto_jsonMto_json_not_implemented

    Inherited fromRunnable(langchain_core)

    Attributes

    AnameAInputTypeAOutputTypeAinput_schemaAoutput_schemaAconfig_specs

    Methods

    Mget_nameMget_input_schemaMget_input_jsonschemaMget_output_schemaMget_output_jsonschemaM
    attribute
    llm_chain: LLMChain

    LLM Chain that generates responses from user input and context.

    attribute
    text_splitter: TextSplitter

    Text splitter that splits the input into chunks.

    attribute
    input_key: str

    Key of the input to the chain.

    attribute
    output_key: str

    Key of the output of the chain.

    attribute
    k: int | None

    Number of questions to generate.

    attribute
    input_keys: list[str]
    attribute
    output_keys: list[str]
    method
    from_llm

    Create a QAGenerationChain from a language model.

    Base class for question-answer generation chains.

    This class is deprecated. See below for an alternative implementation.

    Advantages of this implementation include:

    • Supports async and streaming;
    • Surfaces prompt and text splitter for easier customization;
    • Use of JsonOutputParser supports JSONPatch operations in streaming mode, as well as robustness to markdown.
    from langchain_classic.chains.qa_generation.prompt import (
        CHAT_PROMPT as prompt,
    )
    
    # Note: import PROMPT if using a legacy non-chat model.
    from langchain_core.output_parsers import JsonOutputParser
    from langchain_core.runnables import (
        RunnableLambda,
        RunnableParallel,
        RunnablePassthrough,
    )
    from langchain_core.runnables.base import RunnableEach
    from langchain_openai import ChatOpenAI
    from langchain_text_splitters import RecursiveCharacterTextSplitter
    
    model = ChatOpenAI()
    text_splitter = RecursiveCharacterTextSplitter(chunk_overlap=500)
    split_text = RunnableLambda(lambda x: text_splitter.create_documents([x]))
    
    chain = RunnableParallel(
        text=RunnablePassthrough(),
        questions=(
            split_text | RunnableEach(bound=prompt | model | JsonOutputParser())
        ),
    )
    config_schema
    Mget_config_jsonschema
    Mget_graph
    Mget_prompts
    Mpipe
    Mpick
    Massign
    Minvoke
    Mainvoke
    Mbatch
    Mbatch_as_completed
    Mabatch
    Mabatch_as_completed
    Mstream
    Mastream
    Mastream_log
    Mastream_events
    Mtransform
    Matransform
    Mbind
    Mwith_config
    Mwith_listeners
    Mwith_alisteners
    Mwith_types
    Mwith_retry
    Mmap
    Mwith_fallbacks
    Mas_tool