[Python] Input to ChatPromptTemplate is missing variables {'input', 'agent_scratchpad'}....

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    This code gives me an weird error:

    from langchain_core.output_parsers import StrOutputParser
    from langchain_core.runnables import RunnableLambda, RunnablePassthrough

    def create_weaviate_new_RAG(client, embeddings, llm, class_name_rich, class_properties_rich, class_text_key):

    vector_store = Weaviate(client=client,
    index_name=class_name_rich,
    text_key=class_text_key,
    embedding=embeddings,
    attributes=class_properties_rich,
    #by_text=False,
    )

    retriever=vector_store.as_retriever(
    search_type= "mmr",
    search_kwargs={
    "k": 4,
    "fetch_k": 20,
    }
    )

    prompt = ChatPromptTemplate.from_messages(
    [
    ("system", "You are a helpful assistant who retrieves information from documents"),
    ("user", "{input}"),
    MessagesPlaceholder(variable_name="agent_scratchpad"),
    ]
    )

    rag_pipe = (
    {"context": retriever, "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
    )

    return rag_pipe

    rag_pipe = create_weaviate_new_RAG(client, embeddings, llm_chat, class_name, ["chunk_id", "doc_name", "doc_path"], "chunk_text")
    text = "what is ai policy?"
    rag_pipe.invoke(text)


    Gives me this error:

    "Input to ChatPromptTemplate is missing variables {'input', 'agent_scratchpad'}.
    Expected: ['agent_scratchpad', 'input']
    Received: ['context', 'question']"


    I am using openai==1.7.0 and langchain==0.1.0

    This only started to appear after adding the new rag code from langchain.

    How do I resolve this error?

    Continue reading...

Compartilhe esta Página