1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] LLM not able to parse output using stroutputparser()

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024 às 09:32.

  1. Stack

    Stack Membro Participativo

    I am often getting this error in langchain agent.I am doing a RAG operation and using langchain tools and agents. I use AWS services like bedrock and Lambda for the application. this is How, I have defined agents:

    agent = initialize_agent(
    tools=tools, llm=llm, agent="zero-shot-react-description", verbose=True
    )


    but I am getting error like:

    handle_parsing_errors=True` to the AgentExecutor. This is the error: Could not parse LLM output: ``
    Traceback (most recent call last):
    File "/var/task/src/amaHandler.py", line 365, in lambdaHandler
    finalAnswer = agent.run(query)
    File "/var/lang/lib/python3.10/site-packages/langchain_core/_api/deprecation.py", line 180, in warning_emitting_wrapper
    return wrapped(*args, **kwargs)
    File "/var/lang/lib/python3.10/site-packages/langchain/chains/base.py", line 600, in run
    return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
    File "/var/lang/lib/python3.10/site-packages/langchain_core/_api/deprecation.py", line 180, in warning_emitting_wrapper
    return wrapped(*args, **kwargs)
    File "/var/lang/lib/python3.10/site-packages/langchain/chains/base.py", line 383, in __call__
    return self.invoke(
    File "/var/lang/lib/python3.10/site-packages/langchain/chains/base.py", line 166, in invoke
    raise e
    File "/var/lang/lib/python3.10/site-packages/langchain/chains/base.py", line 156, in invoke
    self._call(inputs, run_manager=run_manager)
    File "/var/lang/lib/python3.10/site-packages/langchain/agents/agent.py", line 1433, in _call
    next_step_output = self._take_next_step(
    File "/var/lang/lib/python3.10/site-packages/langchain/agents/agent.py", line 1139, in _take_next_step
    [
    File "/var/lang/lib/python3.10/site-packages/langchain/agents/agent.py", line 1139, in <listcomp>
    [
    File "/var/lang/lib/python3.10/site-packages/langchain/agents/agent.py", line 1178, in _iter_next_step
    raise ValueError(


    Also to mention I am not getting this error every time, but like 1/5 times.

    My LangSmith shows:

    ValueError: An output parsing error occurred. In order to pass this error back to the agent and have it try again, pass `handle_parsing_errors=True` to the AgentExecutor. This is the error: Could not parse LLM output: ` I now know the final answer to the original input.question
    <|start_header_id|><|start_header_id|>`

    Traceback (most recent call last):
    File "/var/lang/lib/python3.10/site-packages/langchain/agents/agent.py", line 1167, in _iter_next_step
    output = self.agent.plan(
    File "/var/lang/lib/python3.10/site-packages/langchain/agents/agent.py", line 732, in plan
    return self.output_parser.parse(full_output)
    File "/var/lang/lib/python3.10/site-packages/langchain/agents/mrkl/output_parser.py", line 67, in parse
    raise OutputParserException(
    langchain_core.exceptions.OutputParserException: Could not parse LLM output: ` I now know the final answer to the original input.question
    <|start_header_id|><|start_header_id|>`

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/var/task/src/amaHandler.py", line 365, in lambdaHandler
    finalAnswer = agent.run(query)
    File "/var/lang/lib/python3.10/site-packages/langchain_core/_api/deprecation.py", line 180, in warning_emitting_wrapper
    return wrapped(*args, **kwargs)
    File "/var/lang/lib/python3.10/site-packages/langchain/chains/base.py", line 600, in run
    return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
    File "/var/lang/lib/python3.10/site-packages/langchain_core/_api/deprecation.py", line 180, in warning_emitting_wrapper
    return wrapped(*args, **kwargs)
    File "/var/lang/lib/python3.10/site-packages/langchain/chains/base.py", line 383, in __call__
    return self.invoke(
    File "/var/lang/lib/python3.10/site-packages/langchain/chains/base.py", line 166, in invoke
    raise e
    File "/var/lang/lib/python3.10/site-packages/langchain/chains/base.py", line 156, in invoke
    self._call(inputs, run_manager=run_manager)
    File "/var/lang/lib/python3.10/site-packages/langchain/agents/agent.py", line 1433, in _call
    next_step_output = self._take_next_step(
    File "/var/lang/lib/python3.10/site-packages/langchain/agents/agent.py", line 1139, in _take_next_step
    [
    File "/var/lang/lib/python3.10/site-packages/langchain/agents/agent.py", line 1139, in <listcomp>
    [
    File "/var/lang/lib/python3.10/site-packages/langchain/agents/agent.py", line 1178, in _iter_next_step
    raise ValueError(
    ValueError: An output parsing error occurred. In order to pass this error back to the agent and have it try again, pass `handle_parsing_errors=True` to the AgentExecutor. This is the error: Could not parse LLM output: ` I now know the final answer to the original input.question
    <|start_header_id|><|start_header_id|>`


    STRoutputparser generated the answer but agent failed

    Tried what was told by agent: handle_parsing_error = true but didn't work out. Tried to find solutions online but found nothing.

    Tried looking into langchain docs but could'nt find any viable solution .

    Continue reading...

Compartilhe esta Página