Skip to content

sql_agent demo Action and Final Answer appear together to cause an exception #28818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
reatang opened this issue Dec 19, 2024 · 3 comments
Closed
5 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.

Comments

@reatang
Copy link

reatang commented Dec 19, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

# llm = ChatOpenAI()

db = SQLDatabase.from_uri("sqlite:///../somedb/db.sqlite")

agent_executor = create_sql_agent(
    llm=llm,
    db=db,
    verbose=True,
)
agent_executor.handle_parsing_errors=True

resp = agent_executor.invoke("查询三分球命中率最高的球员")
print(resp)

Error Message and Stack Trace (if applicable)

langsmith:

https://smith.langchain.com/public/e8196299-7b02-4314-a38e-bbae8f2f857e/r

Description

I am using sql_agent at an example time, when the agent is currently running, it is not possible to run the program.

My current LLM analysis calculation time is likely to be a hit. includes_answer = FINAL_ANSWER_ACTION in text Use includes_answer == True ,then the result is FINAL_ANSWER_AND_PARSABLE_ACTION_ERROR_MESSAGE

System Info

look langsmith

@langcarl langcarl bot added the investigate Flagged for investigation. label Dec 19, 2024
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Dec 19, 2024
@keenborder786
Copy link
Contributor

Can you try the following:

from langchain_community.utilities import SQLDatabase
from langchain.agents import create_sql_agent
from langchain_openai.chat_models import ChatOpenAI
llm = ChatOpenAI(model="gpt-4")
db = SQLDatabase.from_uri("sqlite:///Chinook.db")
agent_executor = create_sql_agent(
    llm=llm,
    db=db,
    verbose=True,
    agent_executor_kwargs={
        "handle_parsing_errors": True
    }
)
resp = agent_executor.invoke("How many customers are only?")
print(resp)

@reatang
Copy link
Author

reatang commented Dec 20, 2024

yes, i am try.

https://smith.langchain.com/public/971bc360-8f64-4bd3-a020-b512bfe199aa/r

I think it may be the problem with the prompt words, Make Action and Final Answer appear in the same answer.

ReActSingleInputOutputParser@parse

image

Copy link

dosubot bot commented Mar 21, 2025

Hi, @reatang. I'm Dosu, and I'm helping the LangChain team manage their backlog. I'm marking this issue as stale.

Issue Summary

  • You reported an exception in LangChain's sql_agent when "Action" and "Final Answer" appear together in the output.
  • The issue persists even after updating to the latest version, indicating a potential parsing error.
  • @keenborder786 suggested a code snippet to handle parsing errors.
  • You suspect the issue might be related to the prompt structure causing both terms to appear simultaneously.

Next Steps

  • Could you please confirm if this issue is still relevant with the latest version of the LangChain repository? If so, feel free to comment and keep the discussion open.
  • If there is no further activity, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Mar 21, 2025
@reatang reatang closed this as completed Mar 24, 2025
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate Flagged for investigation.
Projects
None yet
Development

No branches or pull requests

2 participants