Skip to content

Commit 7b13292

Browse files
authored
Remove python eval from vector sql db chain (#10937)
<!-- Thank you for contributing to LangChain! Replace this entire comment with: - **Description:** a description of the change, - **Issue:** the issue # it fixes (if applicable), - **Dependencies:** any dependencies required for this change, - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below), - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out! Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally. See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md If you're adding a new integration, please include: 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. It lives in `docs/extras` directory. If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17. -->
1 parent b809c24 commit 7b13292

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

Diff for: libs/experimental/langchain_experimental/sql/vector_sql.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from langchain.chains.sql_database.prompt import PROMPT, SQL_PROMPTS
99
from langchain.prompts.prompt import PromptTemplate
1010
from langchain.schema import BaseOutputParser, BasePromptTemplate
11-
from langchain.schema.base import Embeddings
11+
from langchain.schema.embeddings import Embeddings
1212
from langchain.schema.language_model import BaseLanguageModel
1313
from langchain.tools.sql_database.prompt import QUERY_CHECKER
1414
from langchain.utilities.sql_database import SQLDatabase
@@ -76,23 +76,11 @@ def parse(self, text: str) -> str:
7676
return super().parse(text)
7777

7878

79-
def _try_eval(x: Any) -> Any:
80-
try:
81-
return eval(x)
82-
except Exception:
83-
return x
84-
85-
8679
def get_result_from_sqldb(
8780
db: SQLDatabase, cmd: str
8881
) -> Union[str, List[Dict[str, Any]], Dict[str, Any]]:
8982
result = db._execute(cmd, fetch="all") # type: ignore
90-
if isinstance(result, list):
91-
return [{k: _try_eval(v) for k, v in dict(d._asdict()).items()} for d in result]
92-
else:
93-
return {
94-
k: _try_eval(v) for k, v in dict(result._asdict()).items() # type: ignore
95-
}
83+
return result
9684

9785

9886
class VectorSQLDatabaseChain(SQLDatabaseChain):

0 commit comments

Comments
 (0)