Skip to content

Better error messages on SQL client#93

Merged
lotif merged 3 commits intomainfrom
marcelo/better-sql-error
Mar 26, 2026
Merged

Better error messages on SQL client#93
lotif merged 3 commits intomainfrom
marcelo/better-sql-error

Conversation

@lotif
Copy link
Copy Markdown
Collaborator

@lotif lotif commented Mar 26, 2026

Summary

Raising error on SQL internal method instead of returning False to provide better error messages to the agents. Also:

  • Adding exception logging for better debugging by the devs
  • Updating .env.example to have the Gemini 3.1 models names because Gemini 3 has been deprecated.

Clickup Ticket(s): NA

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test improvements
  • 🔒 Security fix

Changes Made

  • Raising error on SQL internal method instead of returning False to provide better error messages to the agents
  • Adding exception logging for better debugging by the devs
  • Updating .env.example to have the Gemini 3.1 models names because Gemini 3 has been deprecated.

Testing

  • Tests pass locally (uv run pytest tests/)
  • Type checking passes (uv run mypy <src_dir>)
  • Linting passes (uv run ruff check src_dir/)
  • Manual testing performed (describe below)

Manual testing details:

Screenshots/Recordings

Related Issues

Deployment Notes

Checklist

  • Code follows the project's style guidelines
  • Self-review of code completed
  • Documentation updated (if applicable)
  • No sensitive information (API keys, credentials) exposed

@lotif lotif requested a review from amasin2111 March 26, 2026 18:44
logger.exception("SQL Parsing Error: %s", e)
# If we can't parse it, we don't run it.
return False
raise e
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller of this method actually raises a PermissionError:

if not self._is_safe_readonly_query(query):
    raise PermissionError("Security Violation: Query contains prohibited WRITE operations.")

If the error is raised here, then the other one is not required - the caller doesn't need the if statement anymore.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly, those are 2 different error cases.

The caller will raise the PermissionError when this function returns False because it has detected an unsafe statement in the query, for example if it has a DELETE statement.

The function will raise an exception if it encounters an error during the check for unsafe statements, for example if the SQL query has a syntax issue (this is how I found this problem).

It is important that the agent receives two different messages for those two cases so they can fix their SQL statements appropriately.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, right! My mistake

@lotif lotif merged commit 0b9e3ff into main Mar 26, 2026
3 checks passed
@lotif lotif deleted the marcelo/better-sql-error branch March 26, 2026 20:25
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.

2 participants