Reputation: 41
I am facing an error:
ValueError(f"Missing some input keys: {missing_keys}")
from this code. I am trying to parse resumes that are not supposed to have the keywords Name
, phone
, about_me
in them.
However, it parses the keyword it finds similar to the Pydantic class, if prompt is used where I mention setting the field to null if the fields have no information.
Traceback:
Traceback (most recent call last):
File "C:\Users\Sarthak\PycharmProjects\API Resume parser\main.py", line 188, in <module>
info = ExtractInformationFromResume(extracted_text)
File "C:\Users\Sarthak\PycharmProjects\API Resume parser\main.py", line 120, in ExtractInformationFromResume
response = chain.run({"resume": resume})
File "C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site-packages\langchain_core\_api\deprecation.py", line 179, in warning_emitting_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site-packages\langchain\chains\base.py", line 606, in run
return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
File "C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site-packages\langchain_core\_api\deprecation.py", line 179, in warning_emitting_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site-packages\langchain\chains\base.py", line 389, in __call__
return self.invoke(
File "C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site-packages\langchain\chains\base.py", line 170, in invoke
raise e
File "C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site-packages\langchain\chains\base.py", line 158, in invoke
self._validate_inputs(inputs)
File "C:\Users\Sarthak\PycharmProjects\API Resume parser\venv\lib\site-packages\langchain\chains\base.py", line 290, in _validate_inputs
raise ValueError(f"Missing some input keys: {missing_keys}")
ValueError: Missing some input keys: {'\n "ContactInformation"'}
class ContactInformation(BaseModel):
Name: Optional[str] = None
Email: Optional[str] = None
Contact: Optional[str] = None
Links: Optional[List[str]] = None
class Experience(BaseModel):
title: Optional[str] = None
company: Optional[str] = None
duration: Optional[str] = None
class Education(BaseModel):
course: Optional[str] = None
branch: Optional[str] = None
institute: Optional[str] = None
class Projects(BaseModel):
name: Optional[str] = None
description: Optional[str] = None
link: Optional[str] = None
class OutputFormat(BaseModel):
ContactInformation: Optional[ContactInformation] = None
About_Me: Optional[str] = None
Experience: Optional[Union[None, List[Experience]]] = None
Education: Optional[Union[None, List[Education]]] = None
Skills: Optional[List[str]] = None
Certificates: Optional[List[str]] = None
Projects: Optional[Union[None, List[Projects]]] = None
Achievements: Optional[List[str]] = None
Volunteer: Optional[List[str]] = None
Prompt:
PROMPT_2 = """You are given resume : ```{resume}```
Based on the given resume, extract information about the person.
The output should strictly follow the JSON schema below. If a field does not have information, set it to null. Ensure that the email contains an "@" symbol and the contact number is a string of digits. The name is usually found at the beginning of the resume without any labels. Social links should be valid URLs.
{
"ContactInformation": {
"Name": string, // Name of the person, usually at the beginning
"Email": string, // Email address containing "@"
"Contact": string, // Contact number as a string of digits
"Links": [string] // Array of social profile URLs
},
"About_Me": string, // A brief summary about the person
"Experience": [
{
"title": string, // Title of the position
"company": string, // Company name
"duration": string // Duration of employment
}
],
"Education": [
{
"course": string, // Name of the course or subject studied
"branch": string, // Branch or faculty of study
"institute": string // Name of the educational institute
}
],
"Skills": [string], // Array of skills
"Certificates": [string], // Array of certificates
"Projects": [
{
"name": string, // Name of the project
"description": string, // Description of the project
"link": string // URL to the project
}
],
"Achievements": [string], // Array of achievements
"Volunteer": [string] // Array of volunteer work
}
"""
ExtractInformationFromResume function:
def ExtractInformationFromResume(resume: str) -> OutputFormat:
llm = ChatOpenAI(
openai_api_key='*********************************************',
temperature=0.5,
model_name="gpt-3.5-turbo"
)
# Define the output parser
parser = PydanticOutputParser(pydantic_object=OutputFormat)
# Create the prompt template with format instructions
prompt_template = PromptTemplate(
input_variables=["resume"],
template=PROMPT_2,
partial_variables={"format_instructions": parser.get_format_instructions()},
)
# Chain the LLM with the prompt
chain = LLMChain(llm=llm, prompt=prompt_template)
# Run the chain with the resume as input
print(f"Resume Length: {len(resume)} characters")
response = chain.run({"resume": resume})
try:
print("Raw LLM Response:", response)
except Exception as e:
print(f"Error: {str(e)}")
# Parse the LLM response into the expected output format
try:
return OutputFormat(**json.loads(response))
except json.JSONDecodeError:
raise ValueError("Failed to parse response as valid JSON: " + response)
Upvotes: 0
Views: 86