Skip to content

Conversation

@nathan-az
Copy link
Contributor

Raises exception if OutputParsers receive a response with both a valid action and a final answer

Currently, if an OutputParser receives a response which includes both an action and a final answer, they return a FinalAnswer object. This allows the parser to accept responses which propose an action and hallucinate an answer without the action being parsed or taken by the agent.

This PR changes the logic to:

  1. store a variable checking whether a response contains the FINAL_ANSWER_ACTION (this is the easier condition to check).
  2. store a variable checking whether the response contains a valid action
  3. if both are present, raise a new exception stating that both are present
  4. if an action is present, return an AgentAction
  5. if an answer is present, return an AgentAnswer
  6. if neither is present, raise the relevant exception based around the action format (these have been kept consistent with the prior exception messages)

Disclaimer:

  • Existing mock data included strings which did include an action and an answer. This might indicate that prioritising returning AgentAnswer was always correct, and I am patching out desired behaviour? @hwchase17 to advice. Curious if there are allowed cases where this is not hallucinating, and we do want the LLM to output an action which isn't taken.
  • I have not passed send_to_llm through this new exception

Fixes #5601

Who can review?

Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:

@hwchase17 - project lead
@vowelparrot

@nathan-az nathan-az changed the title Raise an exception in MKRL and Chat Output Parsers if parsing text which contains both an actual and a final answer Raise an exception in MKRL and Chat Output Parsers if parsing text which contains both an action and a final answer Jun 3, 2023
Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this lgtm!

@hwchase17 hwchase17 merged commit 26ec845 into langchain-ai:master Jun 4, 2023
@nathan-az nathan-az deleted the fix-output-parser-answer-and-action branch June 5, 2023 00:19
Undertone0809 pushed a commit to Undertone0809/langchain that referenced this pull request Jun 19, 2023
…ich contains both an action and a final answer (langchain-ai#5609)

Raises exception if OutputParsers receive a response with both a valid
action and a final answer

Currently, if an OutputParser receives a response which includes both an
action and a final answer, they return a FinalAnswer object. This allows
the parser to accept responses which propose an action and hallucinate
an answer without the action being parsed or taken by the agent.

This PR changes the logic to:
1. store a variable checking whether a response contains the
`FINAL_ANSWER_ACTION` (this is the easier condition to check).
2. store a variable checking whether the response contains a valid
action
3. if both are present, raise a new exception stating that both are
present
4. if an action is present, return an AgentAction
5. if an answer is present, return an AgentAnswer
6. if neither is present, raise the relevant exception based around the
action format (these have been kept consistent with the prior exception
messages)

Disclaimer:
* Existing mock data included strings which did include an action and an
answer. This might indicate that prioritising returning AgentAnswer was
always correct, and I am patching out desired behaviour? @hwchase17 to
advice. Curious if there are allowed cases where this is not
hallucinating, and we do want the LLM to output an action which isn't
taken.
* I have not passed `send_to_llm` through this new exception

Fixes langchain-ai#5601 

## Who can review?

Community members can review the PR once tests pass. Tag
maintainers/contributors who might be interested:

@hwchase17 - project lead
@vowelparrot
This was referenced Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OutputParsers currently allows model to hallucinate the output of an action

2 participants