Skip to content

Conversation

@zszabo-rh
Copy link
Contributor

@zszabo-rh zszabo-rh commented Jul 23, 2025

Description

This PR introduces structured, multi-select “quick response” feedback categories for negative (thumbs-down) user feedback and removes obsolete / positive categories.

Key points

  1. New FeedbackCategory enum (6 values) – negative-only categories (incorrect, not_relevant, incomplete, outdated_information, unsafe, other) with example comments for each.
  2. FeedbackRequest model updated
    • Adds categories: list[FeedbackCategory] | None
    • Validation ensures at least one of sentiment, user_feedback, or categories is provided.
  3. Endpoint & docs
    • /v1/feedback OpenAPI schema + docs/openapi.(json|md) updated with new field, examples and category table.
  4. Tests
    • All unit tests updated / added to cover the new enum, validation and endpoint behaviour (31 feedback-related tests now pass).

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

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

1. Unit tests

uv run pytest tests/unit/ -k "feedback" -v

All feedback-related tests pass.

2. Manual API verification

curl -X POST http://<host>:<port>/v1/feedback \
     -H "Content-Type: application/json" \
     -d '{
           "conversation_id":"<uuid>",
           "user_question":"What is the capital of France?",
           "llm_response":"Berlin",
           "sentiment":-1,
           "categories":["incorrect"]
         }'

Expected response: {"response":"feedback received"} (HTTP 200).

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added support for structured feedback categories when submitting feedback on AI responses. Users can now select multiple predefined categories (e.g., "incorrect", "not_relevant", "unsafe") to better describe their feedback.
  • Documentation
    • Updated API documentation and examples to include the new feedback categories field and its usage.
  • Tests
    • Expanded test coverage to ensure correct handling, validation, and storage of feedback categories.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 23, 2025

"""

Walkthrough

A new FeedbackCategory enumeration was introduced to standardize structured feedback on AI responses. The FeedbackRequest model and related OpenAPI documentation were updated to include an optional categories field, allowing multiple feedback categories to be submitted. Validators were enhanced to require at least one feedback type among sentiment, user feedback, or categories. Tests were expanded and parameterized to cover the new categories functionality comprehensively.

Changes

File(s) Change Summary
docs/openapi.json, docs/openapi.md Added FeedbackCategory enum and extended FeedbackRequest schema/model with optional categories array; updated docs and examples.
src/models/requests.py Introduced FeedbackCategory enum, added optional categories to FeedbackRequest, updated validators and examples.
tests/unit/app/endpoints/test_feedback.py Parameterized feedback endpoint and storage tests to cover scenarios using the new categories field.
tests/unit/models/test_requests.py Added comprehensive tests for categories in FeedbackRequest, including validation, deduplication, and error cases.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant FeedbackRequestModel

    User->>API: Submit feedback (may include categories)
    API->>FeedbackRequestModel: Validate feedback (sentiment, user_feedback, categories)
    FeedbackRequestModel-->>API: Validation result
    API-->>User: Acknowledge feedback receipt
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~45 minutes

Poem

In the warren, feedback grows anew,
With categories clear, not just a few.
"Too brief! Incomplete!" the rabbits say,
Structured responses guide the way.
Tests now hop through every case,
Ensuring feedback finds its place.
🐇✨
"""

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 generate unit tests to generate unit tests for 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.

@zszabo-rh zszabo-rh marked this pull request as ready for review July 23, 2025 09:21
@zszabo-rh zszabo-rh force-pushed the feedback_category branch from a5508e7 to 318010a Compare July 23, 2025 10:57
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.

Thanks, comments inline

return None # Convert empty list to None for consistency

unique_categories = list(set(value))
return unique_categories
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this validation take into account the "sentiment" field ? Because from L224 says:

"List of feedback categories that describe issues with the LLM response (for negative feedback)."

So I assume, it's only required when feedback is negative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently in assisted chatbot we will use this endpoint that way, as it's more aligned with other implementations, so that the user either gives thumbs up, or thumbs down + optional comment.
But maybe even so the API should not have such constraint. There might be positive categories coming later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, thanks for the explanation

user_question="Test question",
llm_response="Test response",
categories="invalid_type", # Should be list, not string
)
Copy link
Contributor

Choose a reason for hiding this comment

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

We need a test with a positive review (sentiment) and an empty list of categories. Because from what I understood with this change, categories is only required when the feedback is negative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same comment..
so far the user needed to provide either sentiment or feedback, or both
now category is just a 3rd option, any combination would do, until at least one of those is there

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, thanks for the explanation

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.

It LGTM, other teams should also look into this PR to see if it fits the expectations for their use of the feedback API.

user_question="Test question",
llm_response="Test response",
categories="invalid_type", # Should be list, not string
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, thanks for the explanation

return None # Convert empty list to None for consistency

unique_categories = list(set(value))
return unique_categories
Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, thanks for the explanation

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

@zszabo-rh
Copy link
Contributor Author

/cc @tisnik
Hey Pavel, could you please check&approve please?

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.

it looks good, thank you

@zszabo-rh zszabo-rh force-pushed the feedback_category branch from 318010a to 4b256f3 Compare July 25, 2025 06:47
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: 1

🧹 Nitpick comments (2)
src/models/requests.py (1)

261-277: Validate the deduplication logic preserves order.

The validation logic correctly handles None values, empty lists, and type validation. However, the deduplication using list(set(value)) may not preserve the original order of categories.

Consider preserving order while deduplicating:

-        unique_categories = list(set(value))
+        # Preserve order while removing duplicates
+        seen = set()
+        unique_categories = []
+        for category in value:
+            if category not in seen:
+                seen.add(category)
+                unique_categories.append(category)
docs/openapi.md (1)

460-476: Documentation accurately reflects the enum implementation.

The FeedbackCategory table clearly explains each category with appropriate descriptions that match the inline comments in the code.

Consider the static analysis suggestion to replace "completely" with a stronger adverb for better clarity:

-| incorrect | The answer provided is completely wrong |
+| incorrect | The answer provided is entirely wrong |
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a15f073 and 4b256f3.

📒 Files selected for processing (5)
  • docs/openapi.json (3 hunks)
  • docs/openapi.md (3 hunks)
  • src/models/requests.py (6 hunks)
  • tests/unit/app/endpoints/test_feedback.py (3 hunks)
  • tests/unit/models/test_requests.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/unit/app/endpoints/test_feedback.py (2)
src/configuration.py (2)
  • configuration (47-52)
  • user_data_collection_configuration (71-76)
src/app/endpoints/feedback.py (1)
  • store_feedback (104-128)
tests/unit/models/test_requests.py (1)
src/models/requests.py (2)
  • FeedbackRequest (166-291)
  • FeedbackCategory (150-163)
🪛 LanguageTool
docs/openapi.md

[style] ~470-~470: Consider using a different adverb to strengthen your wording.
Context: ...-| | incorrect | The answer provided is completely wrong | | not_relevant | This answer do...

(COMPLETELY_ENTIRELY)

🪛 markdownlint-cli2 (0.17.2)
docs/openapi.md

502-502: Code block style
Expected: fenced; Actual: indented

(MD046, code-block-style)

🔇 Additional comments (10)
src/models/requests.py (3)

150-164: Well-designed enum with clear categorization for negative feedback.

The FeedbackCategory enum is well-structured with descriptive values and inline example comments. The categories cover the primary types of issues users might encounter with AI responses.


201-209: Categories field implementation looks solid.

The field definition is well-documented with appropriate type hints, description, and examples. The multi-select capability aligns well with the PR objectives for structured feedback collection.


279-291: Model validation correctly handles the expanded feedback requirements.

The updated validator properly ensures at least one form of feedback is provided among sentiment, user_feedback, or categories. This addresses the past review discussion about flexibility in feedback types.

docs/openapi.md (1)

489-522: Examples demonstrate proper usage patterns.

The updated documentation includes comprehensive examples showing both basic feedback and feedback with categories, which helps users understand the multi-select capability.

tests/unit/models/test_requests.py (3)

8-8: Import addition supports new test functionality.

The FeedbackCategory import enables testing of the new enum functionality.


211-223: Test method name and logic correctly updated.

The test name change from test_check_sentiment_or_user_feedback to test_check_feedback_provided accurately reflects the expanded validation logic that now includes categories.


237-347: Comprehensive test coverage for categories functionality.

The test suite thoroughly covers all aspects of the categories field:

  • Basic construction with multiple categories
  • Single category usage
  • Deduplication logic
  • Empty list handling
  • Categories-only feedback validation
  • Mixed feedback types
  • All enum values validation
  • Invalid type handling

This provides excellent coverage of the new functionality and edge cases.

tests/unit/app/endpoints/test_feedback.py (2)

51-76: Parameterized tests effectively cover multiple feedback scenarios.

The parameterization approach cleanly tests both scenarios (with and without categories) while maintaining the existing test structure. The test IDs provide clear identification of each scenario.


113-154: Store feedback tests cover diverse payload structures.

The parameterized tests validate that the storage functionality works correctly with both traditional text feedback and the new categories-based feedback, ensuring backward compatibility.

docs/openapi.json (1)

938-958: Verify x-enum-varnames support in downstream tooling

x-enum-varnames is a Pydantic/FastAPI-specific extension rather than a standard OpenAPI 3.1 keyword.
If any of your client-side code generators, documentation builders, or validation gateways read the raw JSON, double-check they gracefully ignore or properly interpret this extension; otherwise they may flag the schema as invalid.
No action needed if your pipeline is already FastAPI-aware, but worth confirming before merging.

Comment on lines +1000 to +1019
"categories": {
"anyOf": [
{
"items": {
"$ref": "#/components/schemas/FeedbackCategory"
},
"type": "array"
},
{
"type": "null"
}
],
"title": "Categories",
"description": "List of feedback categories that apply to the LLM response.",
"examples": [
[
"incorrect",
"incomplete"
]
]
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Schema does not enforce non-empty & unique categories list

The server-side model requires the list to be non-empty & de-duplicated, but the OpenAPI schema leaves those constraints implicit.
Adding minItems and uniqueItems makes the contract self-describing and prevents clients from sending invalid payloads that will be rejected at runtime.

       "items": {
         "$ref": "#/components/schemas/FeedbackCategory"
       },
       "type": "array",
+      "minItems": 1,
+      "uniqueItems": true
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"categories": {
"anyOf": [
{
"items": {
"$ref": "#/components/schemas/FeedbackCategory"
},
"type": "array"
},
{
"type": "null"
}
],
"title": "Categories",
"description": "List of feedback categories that apply to the LLM response.",
"examples": [
[
"incorrect",
"incomplete"
]
]
"categories": {
"anyOf": [
{
"items": {
"$ref": "#/components/schemas/FeedbackCategory"
},
"type": "array",
"minItems": 1,
"uniqueItems": true
},
{
"type": "null"
}
],
"title": "Categories",
"description": "List of feedback categories that apply to the LLM response.",
"examples": [
[
"incorrect",
"incomplete"
]
]
}
🤖 Prompt for AI Agents
In docs/openapi.json around lines 1000 to 1019, the schema for the "categories"
array does not enforce that the list is non-empty and contains unique items. To
fix this, add "minItems": 1 and "uniqueItems": true to the array schema under
"categories" to explicitly require at least one item and ensure all items are
unique, aligning the schema with the server-side model constraints.

@tisnik tisnik merged commit 6459aac into lightspeed-core:main Jul 25, 2025
17 checks passed
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.

4 participants