feat(sql_database): support content_and_artifact in SQLDatabase.run #215
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request addresses issue #30179 by adding support for the
response_format="content_and_artifact"
option in theSQLDatabase.run()
method.Previously, tools like
QuerySQLDatabaseTool
raised aValueError
when this response format was requested, because the underlyingrun()
method always returned a string. With this change, users can now retrieve both the LLM-friendly string output and a structured Python object for programmatic use unblocking important downstream use cases.Changes included in this PR:
langchain_community/utilities/sql_database.py
:run()
method signature now accepts**kwargs
(for backward compatibility and future extensibility).response_format
keyword; when set to"content_and_artifact"
, the method returns a tuple(string_result, processed_result)
.run()
withoutresponse_format
will see no change in behavior.langchain_community/tests/unit_tests/utilities/test_sql_database.py
:SQLDatabase
utility (previously missing).test_sql_database_run_content_and_artifact
to validate both the new tuple-based return and the default string format. This ensures correct behavior and prevents regressions.Fixes #30179