'Input to ChatPromptTemplate is missing variables {\'\\n "subject"\'}. Expected: [\'\\n "subject"\', \'agent_scratchpad\', \'input\'] Received: [\'input\', \'intermediate_steps\', \'agent_scratchpad\']' #22803
Replies: 2 comments
-
Hey @nourbidewe! I'm here to help you with any bugs, questions, or contributions you might have. Let's solve this together! To resolve the Here's how you can modify your code to include these variables:
Here is the updated code: from langchain_core.prompts.chat import ChatPromptTemplate
from langchain_core.prompts import PromptTemplate
from langchain_core.messages import HumanMessagePromptTemplate, MessagesPlaceholder
from langchain_core.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.llms import ChatOpenAI
from pydantic import BaseModel, Field
import json
description_history = []
prompt_3 = '''You are an assistant that extracts subjects from emails as well as a short description of the email and a one-sentence summary of the email.
1. Subject:
- Make the subject short and consistent with predefined categories such as Payment Issue, Maintenance Request, etc.
- Stick to the following subjects to maintain consistency with historical data: Payment Issue, Renewal Request, Maintenance Issue, Neighbors Complaint, Customer Service Complaint, Lease Termination, Parking Issue, App Issue, FAQs, Property Search, Refund Issues, Job Application, Early Termination.
- If you do not find a suitable subject, output "Other" in the field of the JSON file.
2. Description:
- check the historical descriptions first {description_history}. If the email's description matches one from the history, use the historical description as is. If it does not match, output "Other". Never generate a description that is not in the description list!
3. Summary:
- The summary is one sentence that summarizes the email. It can be detailed but always one sentence.
- Below are some samples of summaries:
- Enquired for the availability of 2 bedrooms in wasl 51.
- When is my renewal due?
- Following termination procedures, why is there 545 AED pending on my account balance?
- The quality of work done on my AC is not good.
- What is the status of my NOC ticket?
- Asking for the availability of 3 bedrooms in wasl 51.
4. Output:
- Output the results as a JSON file with keys: subject, description, and summary.
- If you are unable to detect any of the deliverables, output a JSON with all the keys but with value NAN.
- The output should always be JSON, nothing else.
- Always provide a JSON file with the 3 keys specified above!
- Never output a code or a sentence before the JSON file!
Examples:
Example 1:
Input: I am trying to make a payment but it is not working for some reason. I validated that my bank card is valid 100 percent please reply asap.
Output: {{
"subject": "Payment Issue",
"description": "Problems with payment issue for the customer",
"summary": "The customer is trying to make a payment but it's not working for some reason"
}}
'''
@tool
def manage_description_history(description):
"""Check if a similar description exists in the history"""
for saved_description in description_history:
if description in saved_description:
return saved_description
description_history.append(description)
return description
class json_format(BaseModel):
subject: str = Field(description="topic of the email")
description: str = Field(description="description of the email")
summary: str = Field(description="small summary of the email")
def model_function(input):
parser = PydanticOutputParser(pydantic_object=json_format)
format_instructions = parser.get_format_instructions()
prompt = ChatPromptTemplate.from_messages(
[
("system", prompt_3),
("user", "{input}"),
MessagesPlaceholder(variable_name="agent_scratchpad"),
]
)
prompt.partial_variables = {"format_instructions": format_instructions}
model = "gpt-3.5-turbo-1106"
tools = [manage_description_history]
llm = ChatOpenAI(temperature=0, model=model, streaming=True)
agent = create_tool_calling_agent(llm, tools, prompt)
agent_executor = AgentExecutor(
agent=agent,
tools=tools,
handle_parsing_errors=True,
verbose=True,
return_intermediate_steps=True
)
answer = agent_executor.invoke({
"input": input,
"subject": "Payment Issue", # Example subject
"description": "Problems with payment issue for the customer", # Example description
"summary": "The customer is trying to make a payment but it's not working for some reason" # Example summary
})
result_json = json.loads(answer['output'])
return answer['output']
ex_1 = 'what is the policy at your company when it comes to lease termination?'
result1 = model_function(ex_1)
print(result1) In this updated code, the |
Beta Was this translation helpful? Give feedback.
-
i got error like this |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I am trying to use langchain agent to the run these requirement. I want to extract subject, description and summary from an email. For the description, I want the agent to use the tool in order to check if a similar description exist already in the list description history then use it else add it.
I am facing the below error when I am trying to run the code
KeyError: 'Input to ChatPromptTemplate is missing variables {'\n "subject"'}. Expected: ['\n "subject"', 'agent_scratchpad', 'input'] Received: ['input', 'intermediate_steps', 'agent_scratchpad']'
System Info
I am installing the latest version of langchain
Beta Was this translation helpful? Give feedback.
All reactions