mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-01 02:50:47 +00:00
sql: do not hard code the LIMIT clause in the table_info section (#1563)
Seeing a lot of issues in Discord in which the LLM is not using the correct LIMIT clause for different SQL dialects. ie, it's using `LIMIT` for mssql instead of `TOP`, or instead of `ROWNUM` for Oracle, etc. I think this could be due to us specifying the LIMIT statement in the example rows portion of `table_info`. So the LLM is seeing the `LIMIT` statement used in the prompt. Since we can't specify each dialect's method here, I think it's fine to just replace the `SELECT... LIMIT 3;` statement with `3 rows from table_name table:`, and wrap everything in a block comment directly following the `CREATE` statement. The Rajkumar et al paper wrapped the example rows and `SELECT` statement in a block comment as well anyway. Thoughts @fpingham?
This commit is contained in:
@@ -377,18 +377,19 @@
|
||||
"\tFOREIGN KEY(\"GenreId\") REFERENCES \"Genre\" (\"GenreId\"), \n",
|
||||
"\tFOREIGN KEY(\"AlbumId\") REFERENCES \"Album\" (\"AlbumId\")\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"SELECT * FROM 'Track' LIMIT 2;\n",
|
||||
"/*\n",
|
||||
"2 rows from Track table:\n",
|
||||
"TrackId\tName\tAlbumId\tMediaTypeId\tGenreId\tComposer\tMilliseconds\tBytes\tUnitPrice\n",
|
||||
"1\tFor Those About To Rock (We Salute You)\t1\t1\t1\tAngus Young, Malcolm Young, Brian Johnson\t343719\t11170334\t0.99\n",
|
||||
"2\tBalls to the Wall\t2\t2\t1\tNone\t342562\t5510424\t0.99\n"
|
||||
"2\tBalls to the Wall\t2\t2\t1\tNone\t342562\t5510424\t0.99\n",
|
||||
"*/\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/home/jon/projects/langchain/langchain/sql_database.py:121: SAWarning: Dialect sqlite+pysqlite does *not* support Decimal objects natively, and SQLAlchemy must convert from floating point - rounding errors and other issues may occur. Please consider storing Decimal numbers as strings or integers on this platform for lossless storage.\n",
|
||||
"/home/jon/projects/langchain/langchain/sql_database.py:135: SAWarning: Dialect sqlite+pysqlite does *not* support Decimal objects natively, and SQLAlchemy must convert from floating point - rounding errors and other issues may occur. Please consider storing Decimal numbers as strings or integers on this platform for lossless storage.\n",
|
||||
" sample_rows = connection.execute(command)\n"
|
||||
]
|
||||
}
|
||||
@@ -467,12 +468,13 @@
|
||||
"\t\"Composer\" NVARCHAR(220),\n",
|
||||
"\tPRIMARY KEY (\"TrackId\")\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"SELECT * FROM 'Track' LIMIT 3;\n",
|
||||
"/*\n",
|
||||
"3 rows from Track table:\n",
|
||||
"TrackId\tName\tComposer\n",
|
||||
"1\tFor Those About To Rock (We Salute You)\tAngus Young, Malcolm Young, Brian Johnson\n",
|
||||
"2\tBalls to the Wall\tNone\n",
|
||||
"3\tMy favorite song ever\tThe coolest composer of all time\"\"\"\n",
|
||||
"3\tMy favorite song ever\tThe coolest composer of all time\n",
|
||||
"*/\"\"\"\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
@@ -492,11 +494,12 @@
|
||||
"\t\"Name\" NVARCHAR(120), \n",
|
||||
"\tPRIMARY KEY (\"PlaylistId\")\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"SELECT * FROM 'Playlist' LIMIT 2;\n",
|
||||
"/*\n",
|
||||
"2 rows from Playlist table:\n",
|
||||
"PlaylistId\tName\n",
|
||||
"1\tMusic\n",
|
||||
"2\tMovies\n",
|
||||
"*/\n",
|
||||
"\n",
|
||||
"CREATE TABLE Track (\n",
|
||||
"\t\"TrackId\" INTEGER NOT NULL, \n",
|
||||
@@ -504,12 +507,13 @@
|
||||
"\t\"Composer\" NVARCHAR(220),\n",
|
||||
"\tPRIMARY KEY (\"TrackId\")\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"SELECT * FROM 'Track' LIMIT 3;\n",
|
||||
"/*\n",
|
||||
"3 rows from Track table:\n",
|
||||
"TrackId\tName\tComposer\n",
|
||||
"1\tFor Those About To Rock (We Salute You)\tAngus Young, Malcolm Young, Brian Johnson\n",
|
||||
"2\tBalls to the Wall\tNone\n",
|
||||
"3\tMy favorite song ever\tThe coolest composer of all time\n"
|
||||
"3\tMy favorite song ever\tThe coolest composer of all time\n",
|
||||
"*/\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
Reference in New Issue
Block a user