Skip to content

Conversation

@omertuc
Copy link
Contributor

@omertuc omertuc commented Jul 9, 2025

Description

Since LCORE-293 (e60d7df), users can set specify the system prompt in the config, but users can still override it with their queries. This may not be desired in some cases, so this commit adds an option to disable the query system prompt and always use the configured system prompt (or the default one if none is set). If a user tries to use the query system prompt when this option is enabled, an HTTP 422 error is returned with a message explaining that the query system prompt is not supported in this instance.

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Related Tickets & Documents

  • Related Issue #

LCORE-293

  • Closes #

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

I made sure the query prompt was ignored

Summary by CodeRabbit

Summary by CodeRabbit

  • Documentation
    • Clarified system prompt configuration precedence and documented a new option to disable query-level system prompt overrides, including example usage.
  • New Features
    • Added a configuration option to disable the use of query-level system prompts.
  • Bug Fixes
    • Improved logic to respect the new disabling flag when determining which system prompt to use.
  • Tests
    • Added and updated tests to verify correct handling of the new configuration option.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 9, 2025

Walkthrough

A new configuration option, disable_query_system_prompt, was introduced to control whether the system prompt from a query can override the configured system prompt. Documentation and tests were updated to reflect this change. The logic for selecting the system prompt now respects this new flag, defaulting to the configured prompt if disabled.

Changes

File(s) Summary
README.md Documented disable_query_system_prompt option, clarified system prompt precedence, added YAML example.
src/models/config.py Added disable_query_system_prompt field to Customization; renamed validator method.
src/utils/endpoints.py Updated logic to check disable_query_system_prompt before using query's system prompt.
tests/unit/init.py Added disable_query_system_prompt key (default False) to test config dictionary.
tests/unit/test_configuration.py Updated test to include and assert disable_query_system_prompt field in configuration.
tests/unit/utils/test_endpoints.py Refactored tests with pytest fixtures; added tests covering disable_query_system_prompt behavior and error raising.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant Config

    User->>API: Send query (may include system_prompt)
    API->>Config: Check customization & disable_query_system_prompt
    alt disable_query_system_prompt is False
        alt Query includes system_prompt
            API->>API: Use query's system_prompt
        else Query does not include system_prompt
            API->>API: Use configured system_prompt
        end
    else disable_query_system_prompt is True
        API->>API: Use configured system_prompt
    end
Loading

Poem

A toggle for prompts, now added anew,
Choose from the config, or let queries through.
With tests and docs, the logic is tight—
The system prompt flows just as you write.
🐇✨

Now rabbits can hop,
And prompts never flop!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 748bd98 and ecb63cb.

📒 Files selected for processing (6)
  • README.md (1 hunks)
  • src/models/config.py (1 hunks)
  • src/utils/endpoints.py (1 hunks)
  • tests/unit/__init__.py (1 hunks)
  • tests/unit/test_configuration.py (1 hunks)
  • tests/unit/utils/test_endpoints.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (5)
  • tests/unit/test_configuration.py
  • tests/unit/utils/test_endpoints.py
  • src/models/config.py
  • src/utils/endpoints.py
  • tests/unit/init.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-pr
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@omertuc omertuc force-pushed the disablequerysystemprompt branch from f6ddc98 to dc4a394 Compare July 9, 2025 17:58
@omertuc omertuc marked this pull request as ready for review July 9, 2025 17:58
@omertuc omertuc force-pushed the disablequerysystemprompt branch 2 times, most recently from 0592868 to bc71711 Compare July 9, 2025 18:00
@omertuc omertuc changed the title WIP: Add an option to disable query system prompt Add an option to disable query system prompt Jul 9, 2025
Copy link
Contributor

@manstis manstis left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Just a nit-pick for you to consider.

class Customization(BaseModel):
"""Service customization."""

disable_query_system_prompt: Optional[bool] = False
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit picking.

Most of other bool fields are named xxxx_enabled or xxxx_disabled.

For consistency it might be nicer to name this query_system_prompt_disabled.

Copy link
Contributor

@eranco74 eranco74 left a comment

Choose a reason for hiding this comment

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

/lgtm
TBH, I don't know why we have it on the query

Copy link
Contributor

@tisnik tisnik left a comment

Choose a reason for hiding this comment

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

approved, but pls look at @manstis comment

@eranco74
Copy link
Contributor

eranco74 commented Jul 9, 2025

If query_system_prompt_disabled is set to true, and we didn't configure a system prompt, what will the agent use?
The default system prompt?

@tisnik
Copy link
Contributor

tisnik commented Jul 9, 2025

If query_system_prompt_disabled is set to true, and we didn't configure a system prompt, what will the agent use? The default system prompt?

yes

@umago
Copy link
Contributor

umago commented Jul 10, 2025

@eranco74 when I was doing the /query, I mimic what was available in the road-core/service /query endpoint. And the system_prompt was a parameter.

Now, if nobody uses it and if we see it as a problem. Let's get rid of it before there's any release instead of having 3 different ways of configurating the system_prompt ?

What you folks think ? I think we should make things simple and straight-forward, adding a new config to disable something in the API makes the use of that strange.

With this patch, when the config is enabled and the user make a request to the /query endpoint with the system_prompt set, the service will return 200 saying the request was accepted but in reality part of it was ignored. It sounds off to me.

@omertuc
Copy link
Contributor Author

omertuc commented Jul 10, 2025

The only advantage I can think of, of having the system prompt in the query, is that it allows people to create a wrapper service around lightspeed stack which will act as e.g. multiple different chat bots, backed by a single lightspeed stack instance (and that wrapper can freely vary the prompt). So it's not entirely useless.

I make no such requirement myself, but I'm just putting this idea out there in case you want to consider it. I have no strong opinion either way

)


def get_system_prompt(query_request: QueryRequest, configuration: AppConfig) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

So now, if user makes a request to the API with the system_prompt set. The service will return 200 saying it was accepted but, if this new option is enabled. The request was just partially accept right ? As part of it will be ignored.

I don't like it, I think that we should just get rid of the system_prompt parameter in the /query endpoint. Make the service simple, because now we have too many ways of configuring/overriding the same thing.

Copy link
Contributor Author

@omertuc omertuc Jul 10, 2025

Choose a reason for hiding this comment

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

So now, if user makes a request to the API with the system_prompt set. The service will return 200 saying it was accepted but, if this new option is enabled. The request was just partially accept right ? As part of it will be ignored.

Yes

I don't like it

I don't love it either, it was an arbitrary decision, I can make it an error

I think that we should just get rid of the system_prompt parameter in the /query endpoint. Make the service simple, because now we have too many ways of configuring/overriding the same thing.

I'm also fine with this, but I've proposed a situation why it might make sense in the comment above, so you might want to reconsider. FWIW I have no stakes in this

@umago
Copy link
Contributor

umago commented Jul 10, 2025

The only advantage I can think of, of having the system prompt in the query, is that it allows people to create a wrapper service around lightspeed stack which will act as multiple different chat bots, backed by a single lightspeed stack instance (and that wrapper can freely vary the prompt). So it's not entirely useless.

I make no such requirement myself, but I'm just putting this idea out there in case you want to consider it. I have no strong opinion either way

Right, I can see that too but, I don't think that's a requirement for any Lightspeed-* at the moment. Seems a bit of over engineering if we allow it for now. If someone come up with a requirement for that, then yes, we can add it. But doing it prior to any requirements seems not worth it.

@umago
Copy link
Contributor

umago commented Jul 10, 2025

Ok so speaking with other folks, the "system_prompt" parameter does have some usage. We then agreed on raising an error when the option that disable the system_prompt is enabled and a user makes a request with the system_prompt set.

That would solve the issue and makes the API usage clear from the user perspective. Thanks for the patch!

@manstis
Copy link
Contributor

manstis commented Jul 10, 2025

FWIW, the Ansible Chatbot makes use of road-core's QueryRequest.system_prompt to override the system_prompt without having to build a new backend service image with it statically configured.. It has been very useful when working on "prompt engineering" to be able to quickly try new system_prompt's during development.

There are probably other approaches that could be taken if it was removed from lightspeed-stack.

@umago
Copy link
Contributor

umago commented Jul 10, 2025

Thanks @manstis for the feedback. Yeah, I can see the benefit of it now. Speaking with @omertuc, we decided to throw an error when the option to disable query_system_prompt is set and the user sends a request with a system_prompt.

I think that's fair because, we don't just sneakely change or ignore parts of the user request and also we keep the endpoint for the cases like yours. Does that work for you ?

@manstis
Copy link
Contributor

manstis commented Jul 10, 2025

Does that work for you ?

@umago Yes, absolutely. Thank-you.

@omertuc omertuc force-pushed the disablequerysystemprompt branch 2 times, most recently from b63ffc6 to 748bd98 Compare July 10, 2025 09:38
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/unit/utils/test_endpoints.py (1)

80-142: Consider adding edge case tests for completeness.

The current test suite is comprehensive, but consider adding tests for:

  1. When disable_query_system_prompt is True but no configured system prompt is set (should fall back to default)
  2. When disable_query_system_prompt is explicitly set to False (should behave like the default case)
def test_get_system_prompt_with_disable_query_system_prompt_no_config(
    config_without_system_prompt, query_request_with_system_prompt
):
    """Test that default system prompt is used when query system prompt is disabled and no config is set."""
    # Modify config to disable query system prompt
    config_without_system_prompt.customization = type('obj', (object,), {
        'system_prompt': None,
        'disable_query_system_prompt': True
    })()
    
    with pytest.raises(HTTPException) as exc_info:
        endpoints.get_system_prompt(
            query_request_with_system_prompt,
            config_without_system_prompt,
        )
    assert exc_info.value.status_code == 422
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc71711 and 748bd98.

📒 Files selected for processing (6)
  • README.md (1 hunks)
  • src/models/config.py (1 hunks)
  • src/utils/endpoints.py (1 hunks)
  • tests/unit/__init__.py (1 hunks)
  • tests/unit/test_configuration.py (1 hunks)
  • tests/unit/utils/test_endpoints.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/utils/endpoints.py
  • src/models/config.py
  • README.md
  • tests/unit/init.py
  • tests/unit/test_configuration.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-pr
🔇 Additional comments (8)
tests/unit/utils/test_endpoints.py (8)

5-5: Good addition of HTTPException import.

The import is necessary for testing the error handling behavior of the new feature.


14-14: Excellent extraction of constant for reuse.

Using a module-level constant for the configured system prompt improves maintainability and reduces duplication across test fixtures.


26-65: Well-designed fixtures for comprehensive test coverage.

The three configuration fixtures properly cover different scenarios:

  1. No customization
  2. Custom system prompt only
  3. Custom system prompt with disabled query system prompt

The fixture design follows pytest best practices and ensures proper test isolation.


68-77: Clean and focused query request fixtures.

The fixtures provide clear separation between requests with and without system prompts, making test intentions explicit.


80-118: Comprehensive coverage of core functionality.

The first four test functions properly validate the existing system prompt selection logic:

  • Default prompt when no customization
  • Configured prompt when no query prompt
  • Query prompt takes precedence over default
  • Query prompt takes precedence over configured prompt

The test logic is correct and assertions are appropriate.


120-130: Excellent error handling test for the new feature.

The test correctly validates that an HTTPException with status code 422 is raised when a query system prompt is provided while the feature is disabled. This ensures proper API contract enforcement.


133-142: Good validation of allowed behavior with disabled feature.

The test confirms that queries without system prompts are still allowed when the feature is disabled, and the configured system prompt is properly used. This ensures the feature doesn't break normal operation.


9-9: Import path for config_dict verified
config_dict is defined and exported in tests/unit/__init__.py, so from tests.unit import config_dict is valid. No changes needed.

Copy link
Contributor

@umago umago left a comment

Choose a reason for hiding this comment

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

Other than the pylint error, the code LGTM now

Since LCORE-293 (e60d7df), users can
set specify the system prompt in the config, but users can still
override it with their queries. This may not be desired in some cases,
so this commit adds an option to disable the query system prompt and
always use the configured system prompt (or the default one if none is
set). If a user tries to use the query system prompt when this option is
enabled, an HTTP 422 error is returned with a message explaining that
the query system prompt is not supported in this instance.
@omertuc omertuc force-pushed the disablequerysystemprompt branch from 748bd98 to ecb63cb Compare July 10, 2025 09:45
@tisnik tisnik merged commit d501148 into lightspeed-core:main Jul 10, 2025
17 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 21, 2025
18 tasks
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.

5 participants