You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The retry behavior is as expected when I use the RetryOutputParser with an inner parser that throws an error. Still, the LangSmith traces don't show either the execution of the Retry parser explicitly (as it occurs with other parsers like the PydanticOutputParser) or the inner output parser that threw the error.
The last one looks very important in showing what caused the error in the traces.
Is this expected or a possible problem?
Code to reproduce:
fromlangchain.output_parsersimportRetryOutputParserfromlangchain_core.output_parsers.pydanticimportPydanticOutputParserfromlangchain_core.pydantic_v1importBaseModelfromlangchain_openaiimportChatOpenAIfromlangchain_core.runnablesimportRunnableLambda, RunnableParallelfromlangchain_core.exceptionsimportOutputParserExceptionimportosos.environ["LANGCHAIN_TRACING_V2"] ="true"os.environ["LANGCHAIN_PROJECT"] ="Test"os.environ["LANGCHAIN_ENDPOINT"] ="https://api.smith.langchain.com"os.environ["LANGCHAIN_API_KEY"] ="lsv2_**********"fromlangchain_core.promptsimport (
PromptTemplate,
)
classCustomParser(PydanticOutputParser):
defparse(self, output: str) ->dict:
raiseOutputParserException("Failed to parse")
@propertydef_type(self) ->str:
return"custom_parser_throw_exception"classTestModel(BaseModel):
a: intb: strparser=CustomParser(pydantic_object=TestModel)
model=ChatOpenAI(temperature=0)
retry_parser=RetryOutputParser.from_llm(parser=parser, llm=model, max_retries=3)
prompt=PromptTemplate(
template="Answer the user query.\n{format_instructions}\n{query}\n",
input_variables=["query"],
partial_variables={"format_instructions": parser.get_format_instructions()},
)
completion_chain=prompt|modelmain_chain=RunnableParallel(
completion=completion_chain, prompt_value=prompt
) |RunnableLambda(lambdax: retry_parser.parse_with_prompt(**x))
print(main_chain.invoke({"query": "who is leo di caprios gf?"}))
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The retry behavior is as expected when I use the RetryOutputParser with an inner parser that throws an error. Still, the LangSmith traces don't show either the execution of the Retry parser explicitly (as it occurs with other parsers like the PydanticOutputParser) or the inner output parser that threw the error.
The last one looks very important in showing what caused the error in the traces.
Is this expected or a possible problem?
Code to reproduce:
Link to the trace in LangSmith: https://smith.langchain.com/public/eb7ec0ac-d165-4883-b66f-c0991adea315/r
Beta Was this translation helpful? Give feedback.
All reactions