Skip to content

feat(sql_database): support content_and_artifact in SQLDatabase.run #215

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

diego-coder
Copy link

@diego-coder diego-coder commented Jul 31, 2025

Description

This pull request addresses issue #30179 by adding support for the response_format="content_and_artifact" option in the SQLDatabase.run() method.

Previously, tools like QuerySQLDatabaseTool raised a ValueError when this response format was requested, because the underlying run() 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:

  1. langchain_community/utilities/sql_database.py:

    • The run() method signature now accepts **kwargs (for backward compatibility and future extensibility).
    • Added logic to check for a response_format keyword; when set to "content_and_artifact", the method returns a tuple (string_result, processed_result).
    • The artifact returned is the post-processed result (with truncated strings), matching the structure of what is returned to the LLM in string form.
    • Updated the method docstring to Google-style.
    • Backward compatibility: Existing code using run() without response_format will see no change in behavior.
  2. langchain_community/tests/unit_tests/utilities/test_sql_database.py:

    • Created a new unit test file for the core SQLDatabase utility (previously missing).
    • Added 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

@diego-coder diego-coder force-pushed the fix/sql-tool-artifact-30179 branch from b94c4be to b6ab6f5 Compare July 31, 2025 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQLDatabase / QuerySQLDatabaseTool does not support tool option response_format="content_and_artifact"
1 participant