Skip to content

Conversation

@ravikiranvm
Copy link
Contributor

@ravikiranvm ravikiranvm commented Nov 27, 2025

Fixes OPS-3138

Additional Notes

Screenshot 2025-11-27 at 3 40 36 PM

Although it's not happening most of the times, LLM once included session-sql tool in the tool selection output even for a simple query like do you have access to my tables?

I've checked the description of this tool:
Screenshot 2025-11-27 at 3 44 48 PM

The description is kinda generic and may not be clear for LLM to use it correctly in our app. So I've modified the system prompt to clarify the scope of this tool


Alternative fix: Do we really need this session-sql tool? Can we exclude it from the tools selection?

@linear
Copy link

linear bot commented Nov 27, 2025

@coderabbitai
Copy link

coderabbitai bot commented Nov 27, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ops-3138

Comment @coderabbitai help to get the list of available commands and usage tips.

@ravikiranvm ravikiranvm changed the title Add system prompt to clarify the scope of tool Add system prompt to clarify the scope of session-sql tool Nov 27, 2025
@ravikiranvm ravikiranvm marked this pull request as ready for review November 27, 2025 10:20
Copilot AI review requested due to automatic review settings November 27, 2025 10:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds clarification to the system prompt about the specific scope of the session-sql tool to prevent LLM from incorrectly selecting it for general database queries. The tool is meant exclusively for AWS cost/billing MCP tool-generated tables and temporary analysis, not for user database queries.

  • Added explicit guidance in the system prompt defining when the session-sql tool should be used

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@greptile-apps
Copy link

greptile-apps bot commented Nov 27, 2025

Greptile Overview

Greptile Summary

Added clarifying note to the LLM system prompt to prevent incorrect tool selection for the session-sql tool. The note specifies that session-sql is only for AWS cost/billing MCP-created tables, not for general user database queries.

  • Addresses issue where LLM occasionally selected session-sql for general database queries
  • Improves tool routing accuracy by explicitly defining the scope of session-sql
  • Minor grammatical suggestion: "user's" → "the user's"

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is a simple, targeted addition to a system prompt that clarifies tool usage scope. It's a single line addition that improves LLM decision-making without affecting logic or introducing side effects. The change addresses a real issue observed in production and follows the existing pattern of prompt engineering in the codebase.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/server/api/src/app/ai/mcp/llm-query-router.ts 5/5 Added clarifying note to system prompt about session-sql tool scope to prevent incorrect LLM tool selection for general database queries

Sequence Diagram

sequenceDiagram
    participant User
    participant LLM as LLM Query Router
    participant SystemPrompt as getSystemPrompt()
    participant LLMModel as Language Model

    User->>LLM: routeQuery(messages, tools, ...)
    LLM->>SystemPrompt: Generate system prompt
    Note over SystemPrompt: Adds clarifying note:<br/>"session-sql tool is ONLY<br/>for AWS cost/billing tables"
    SystemPrompt-->>LLM: Return enhanced prompt
    LLM->>LLMModel: generateObject(system prompt + messages)
    LLMModel-->>LLM: Returns tool_names & classification
    Note over LLMModel: Now correctly excludes<br/>session-sql for general<br/>database queries
    LLM-->>User: Selected tools & classification
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

`IMPORTANT: Tables tools should always be included in the output if the user asks a question involving those table names: ${openopsTablesNames.join(
', ',
)}. ` +
"NOTE: The 'session-sql' tool is ONLY for querying tables created by AWS cost/billing MCP tools and performing temporary analysis. It is NOT for user's database or table related queries. " +
Copy link

Choose a reason for hiding this comment

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

style: Grammatical issue: "user's" should be "the user's" for clarity

Suggested change
"NOTE: The 'session-sql' tool is ONLY for querying tables created by AWS cost/billing MCP tools and performing temporary analysis. It is NOT for user's database or table related queries. " +
"NOTE: The 'session-sql' tool is ONLY for querying tables created by AWS cost/billing MCP tools and performing temporary analysis. It is NOT for the user's database or table related queries. " +
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/server/api/src/app/ai/mcp/llm-query-router.ts
Line: 210:210

Comment:
**style:** Grammatical issue: "user's" should be "the user's" for clarity

```suggestion
    "NOTE: The 'session-sql' tool is ONLY for querying tables created by AWS cost/billing MCP tools and performing temporary analysis. It is NOT for the user's database or table related queries. " +
```

How can I resolve this? If you propose a fix, please make it concise.

@sonarqubecloud
Copy link

`IMPORTANT: Tables tools should always be included in the output if the user asks a question involving those table names: ${openopsTablesNames.join(
', ',
)}. ` +
"NOTE: The 'session-sql' tool is ONLY for querying tables created by AWS cost/billing MCP tools and performing temporary analysis within the session. It is NOT for user's database or table related queries. " +
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like this @ravikiranvm .
There might be other tools in the future that cause this problem.
I think a broader solution is needed, to say that certain tools do not mix with each other.
Please consult with Eran.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will talk to Eran.

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.

3 participants