Enhance SQLDatabaseChain with SQL Results in Intermediate Steps Dictionary
Labels: name: auto:enhancement, name: auto:documentation

### Feature request

## Description

Currently, the SQLDatabaseChain class is designed to optionally return intermediate steps taken during the SQL command generation and execution. These intermediate steps are helpful in understanding the processing flow, especially during debugging or for logging purposes. However, these intermediate steps do not store the SQL results obtained at various steps, which could offer deeper insights and can aid in further optimizations or analyses.

This feature request proposes to enhance the SQLDatabaseChain class to save SQL results from intermediate steps into a dictionary, akin to how SQL commands are currently stored. This would not only facilitate a more comprehensive view of each step but also potentially help in identifying and fixing issues or optimizing the process further.

### Motivation

#### Insightful Debugging: 
Storing SQL results in intermediate steps will facilitate deeper insights during debugging, helping to pinpoint the exact step where a potential issue might be occurring.

#### Enhanced Logging: 
Logging the SQL results at each step can help in creating a more detailed log, which can be instrumental in analyzing the performance and identifying optimization opportunities.

Improved Analysis and Optimization: With the SQL results available at each step, it becomes feasible to analyze the results at different stages, which can be used to further optimize the SQL queries or the process flow.

### Your contribution

I propose to contribute to implementing this feature by:

#### Code Adaptation: 
Modifying the _call_ method in the SQLDatabaseChain class to include SQL results in the intermediate steps dictionary, similar to how sql_cmd is currently being saved.

#### Testing: 
Developing appropriate unit tests to ensure the correct functioning of the new feature, and that it does not break the existing functionality.

#### Documentation: 
Updating the documentation to include details of the new feature, illustrating how to use it and how it can benefit the users.

#### Optimization: 
Once implemented, analyzing the stored results to propose further optimizations or enhancements to the Langchain project.

## Proposed Changes
In the _call_ method within the SQLDatabaseChain class:

Amend the intermediate steps dictionary to include a new key, say sql_result, where the SQL results at different stages would be saved.

During the SQL execution step, save the SQL result into the sql_result key in the intermediate steps dictionary, similar to how sql_cmd is being saved currently.

```
if not self.use_query_checker:
    ...
    intermediate_steps.append({"sql_cmd": sql_cmd, "sql_result": str(result)})  # Save sql result here
else:
    ...
    intermediate_steps.append({"sql_cmd": checked_sql_command, "sql_result": str(result)})  # Save sql result here
```
I believe that this contribution would be a valuable addition to the Langchain project, and I am eager to collaborate with the team to make it a reality.

Looking forward to hearing your thoughts on this proposal.