Open jyoti194 opened 2 weeks ago
@dasubot
These are all LLM issues i'm afraid. You'll need to come up with better ways of formatting your prompts, and maybe hardcoding parts of the SQL query. This isn't really anything wrong with Langchain or AgentExecutor, I don't believe. Can you look in Langsmith and share the execution? Just incase?
Checked other resources
Example Code
from langchain.sql_database import SQLDatabase from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder,PromptTemplate from langchain.tools import BaseTool from langchain.tools.render import format_tool_to_openai_function from langchain.schema.runnable import Runnable,RunnableLambda,RunnableParallel from langchain.chat_models import ChatOpenAI from langchain.agents.format_scratchpad import format_to_openai_function_messages from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser from langchain.agents import AgentExecutor from pydantic import BaseModel, Field import os from secret_key import openapi_key from sqlalchemy import create_engine import constants from datetime import datetime import re from typing import Optional
os.environ['OPENAI_API_KEY'] = 'sk-xxxxxxxxxxxx'
os.environ['OPENAI_API_KEY'] = openapi_key
def chat5(question: str):
result= chat5("insert personal allowance of 6000 to employee id TA*** for feb 2024, given by 3003") print(result)
Error Message and Stack Trace (if applicable)
Invoking:
sql_db_manipulation
with{'user_query': "INSERT INTO PAY_transaction_settingallow (euid, alw_id, amount, effect_date, to_date, createDate, givenBy) SELECT ed.employeeEuid, pma.alw_id, 6000, '2024-02-01', '2024-02-29', GETDATE(), '3003' FROM employee_details ed JOIN pay_mst_allowance pma ON ed.employeeName = 'TA*******' AND (pma.alw_desc = 'personal allowance' OR pma.short_name = 'personal allowance') WHERE NOT EXISTS (SELECT 1 FROM PAY_transaction_settingallow WHERE euid = ed.employeeEuid AND alw_id = pma.alw_id AND effect_date = '2024-02-01' AND to_date = '2024-02-29' AND amount = 6000)"}
The SQL query has been executed successfully.The personal allowance of 6000 has been inserted for employee ID TA*** for February 2024, given by 3003.
Description
in the output result of AgentExecutor its give the result as "The personal allowance of 6000 has been inserted for employee ID TA for February 2024, given by 3003. " but there is an error in the sql query written there as it's taking employee name instead of employeeID, in that case it should give the output something like "query is not executed" or "0 rows effectd" instead of giving as "The personal allowance of 6000 has been inserted for employee ID TA for February 2024, given by 3003." in lot of cases its happening the same when its not done any changes in table still its giving the output has "has been inserted" or "has been updated"
i have written a logic to handle it externally, but that doesn't seems to work, so how to resolve this issue?
System Info
python: 3.11 langchain: latest os: windows