Replies: 4 comments 11 replies
-
Hey @pjathul10! Long time, no chat. Hope you've been coding up a storm! What's cooking in your code kitchen today? Based on the error message you provided, it seems like the output from the language model is not valid JSON, which is causing the The Here is an example of what the output should look like: {
"nodes": [
{ "id": "Marie Curie", "type": "person" },
{ "id": "Poland", "type": "country" },
// More nodes...
],
"relationships": [
{
"source": { "id": "Marie Curie", "type": "person" },
"target": { "id": "Poland", "type": "country" },
"type": "NATIONALITY"
},
// More relationships...
]
} If the output from the language model does not match this format, the To resolve this issue, you could try the following steps:
If you're still encountering the issue after trying these steps, please provide more details about the output from the language model and the exact steps you are taking to process it. This will help us better understand the issue and provide more targeted assistance. For more information about the Sources
|
Beta Was this translation helpful? Give feedback.
-
The code is working perfectly fine for me. Try to update dependencies I have this output :
Is it what you are expecting ? Here is my config :
|
Beta Was this translation helpful? Give feedback.
-
Updating the dependencies does not solve my problem. can you suggest some kind of modifications or solutions for this one? |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I am trying to create Knowledge graph from unstructured data but getting some error with respect to the output
OutputParserException Traceback (most recent call last)
Cell In[5], line 18
11 text = """
12 Marie Curie, was a Polish and naturalised-French physicist and chemist who conducted pioneering research on radioactivity.
13 She was the first woman to win a Nobel Prize, the first person to win a Nobel Prize twice, and the only person to win a Nobel Prize in two scientific fields.
14 Her husband, Pierre Curie, was a co-winner of her first Nobel Prize, making them the first-ever married couple to win the Nobel Prize and launching the Curie family legacy of five Nobel Prizes.
15 She was, in 1906, the first woman to become a professor at the University of Paris.
16 """
17 documents = [Document(page_content=text)]
---> 18 graph_documents = llm_transformer.convert_to_graph_documents(documents)
19 print(f"Nodes:{graph_documents[0].nodes}")
20 print(f"Relationships:{graph_documents[0].relationships}")
File ~\AppData\Local\anaconda3\Lib\site-packages\langchain_experimental\graph_transformers\llm.py:264, in LLMGraphTransformer.convert_to_graph_documents(self, documents)
262 results = []
263 for document in documents:
--> 264 graph_document = self.process_response(document)
265 results.append(graph_document)
266 return results
File ~\AppData\Local\anaconda3\Lib\site-packages\langchain_experimental\graph_transformers\llm.py:207, in LLMGraphTransformer.process_response(self, document)
202 """
203 Processes a single document, transforming it into a graph document using
204 an LLM based on the model's schema and constraints.
205 """
206 text = document.page_content
--> 207 raw_schema = self.chain.invoke({"input": text})
208 if raw_schema.nodes:
209 nodes = [map_to_base_node(node) for node in raw_schema.nodes]
File ~\AppData\Local\anaconda3\Lib\site-packages\langchain_core\runnables\base.py:2218, in RunnableSequence.invoke(self, input, config)
2216 try:
2217 for i, step in enumerate(self.steps):
-> 2218 input = step.invoke(
2219 input,
2220 # mark each step as a child run
2221 patch_config(
2222 config, callbacks=run_manager.get_child(f"seq:step:{i+1}")
2223 ),
2224 )
2225 # finish the root run
2226 except BaseException as e:
File ~\AppData\Local\anaconda3\Lib\site-packages\langchain_core\output_parsers\base.py:169, in BaseOutputParser.invoke(self, input, config)
165 def invoke(
166 self, input: Union[str, BaseMessage], config: Optional[RunnableConfig] = None
167 ) -> T:
168 if isinstance(input, BaseMessage):
--> 169 return self._call_with_config(
170 lambda inner_input: self.parse_result(
171 [ChatGeneration(message=inner_input)]
172 ),
173 input,
174 config,
175 run_type="parser",
176 )
177 else:
178 return self._call_with_config(
179 lambda inner_input: self.parse_result([Generation(text=inner_input)]),
180 input,
181 config,
182 run_type="parser",
183 )
File ~\AppData\Local\anaconda3\Lib\site-packages\langchain_core\runnables\base.py:1405, in Runnable._call_with_config(self, func, input, config, run_type, **kwargs)
1401 context = copy_context()
1402 context.run(var_child_runnable_config.set, child_config)
1403 output = cast(
1404 Output,
-> 1405 context.run(
1406 call_func_with_variable_args, # type: ignore[arg-type]
1407 func, # type: ignore[arg-type]
1408 input, # type: ignore[arg-type]
1409 config,
1410 run_manager,
1411 **kwargs,
1412 ),
1413 )
1414 except BaseException as e:
1415 run_manager.on_chain_error(e)
File ~\AppData\Local\anaconda3\Lib\site-packages\langchain_core\runnables\config.py:326, in call_func_with_variable_args(func, input, config, run_manager, **kwargs)
324 if run_manager is not None and accepts_run_manager(func):
325 kwargs["run_manager"] = run_manager
--> 326 return func(input, **kwargs)
File ~\AppData\Local\anaconda3\Lib\site-packages\langchain_core\output_parsers\base.py:170, in BaseOutputParser.invoke..(inner_input)
165 def invoke(
166 self, input: Union[str, BaseMessage], config: Optional[RunnableConfig] = None
167 ) -> T:
168 if isinstance(input, BaseMessage):
169 return self._call_with_config(
--> 170 lambda inner_input: self.parse_result(
171 [ChatGeneration(message=inner_input)]
172 ),
173 input,
174 config,
175 run_type="parser",
176 )
177 else:
178 return self._call_with_config(
179 lambda inner_input: self.parse_result([Generation(text=inner_input)]),
180 input,
181 config,
182 run_type="parser",
183 )
File ~\AppData\Local\anaconda3\Lib\site-packages\langchain_core\output_parsers\openai_tools.py:124, in PydanticToolsParser.parse_result(self, result, partial)
123 def parse_result(self, result: List[Generation], *, partial: bool = False) -> Any:
--> 124 json_results = super().parse_result(result, partial=partial)
125 if not json_results:
126 return None if self.first_tool_only else []
File ~\AppData\Local\anaconda3\Lib\site-packages\langchain_core\output_parsers\openai_tools.py:80, in JsonOutputToolsParser.parse_result(self, result, partial)
78 final_tools.append(parsed)
79 if exceptions:
---> 80 raise OutputParserException("\n\n".join(exceptions))
81 if self.first_tool_only:
82 return final_tools[0] if final_tools else None
OutputParserException: Function DynamicGraph arguments:
({
nodes: [
{ id: "Marie Curie", type: "person" },
{ id: "Poland", type: "country" },
{ id: "France", type: "country" },
{ id: "physicist", type: "occupation" },
{ id: "chemist", type: "occupation" },
{ id: "Nobel Prize", type: "award" },
{ id: "Pierre Curie", type: "person" },
{ id: "University of Paris", type: "university" }
],
relationships: [
{
source: { id: "Marie Curie", type: "person" },
target: { id: "Poland", type: "country" },
type: "NATIONALITY"
},
{
source: { id: "Marie Curie", type: "person" },
target: { id: "France", type: "country" },
type: "NATIONALITY"
},
{
source: { id: "Marie Curie", type: "person" },
target: { id: "physicist", type: "occupation" },
type: "OCCUPATION"
},
{
source: { id: "Marie Curie", type: "person" },
target: { id: "chemist", type: "occupation" },
type: "OCCUPATION"
},
{
source: { id: "Marie Curie", type: "person" },
target: { id: "Nobel Prize", type: "award" },
type: "AWARD"
},
{
source: { id: "Marie Curie", type: "person" },
target: { id: "University of Paris", type: "university" },
type: "PROFESSOR"
},
{
source: { id: "Pierre Curie", type: "person" },
target: { id: "Marie Curie", type: "person" },
type: "MARRIED_TO"
},
{
source: { id: "Pierre Curie", type: "person" },
target: { id: "Nobel Prize", type: "award" },
type: "AWARD"
}
]
})
are not valid JSON. Received JSONDecodeError Expecting value: line 1 column 1 (char 0)
System Info
System Information
Package Information
Packages not installed (Not Necessarily a Problem)
The following packages were not found:
Beta Was this translation helpful? Give feedback.
All reactions