RHIDP-14308: add saved prompts GET/POST/DELETE endpoints#2214
RHIDP-14308: add saved prompts GET/POST/DELETE endpoints#2214Jdubrick wants to merge 12 commits into
Conversation
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
|
Warning Review limit reached
Next review available in: 23 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
WalkthroughAdds an authenticated ChangesSaved prompts listing
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
actor Client
participant AuthDependency
participant list_saved_prompts_handler
participant list_saved_prompts_by_user
Client->>AuthDependency: GET /v1/saved-prompts
AuthDependency->>list_saved_prompts_handler: AuthTuple
list_saved_prompts_handler->>list_saved_prompts_by_user: user_id
list_saved_prompts_by_user-->>list_saved_prompts_handler: saved prompt rows
list_saved_prompts_handler-->>Client: SavedPromptsListResponse
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 7✅ Passed checks (7 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app/endpoints/saved_prompts.py`:
- Around line 137-156: Update the logging in the saved-prompts retrieval flow to
remove user_id from both the initial retrieval message and the SQLAlchemyError
message, while retaining operation context and exception details. Keep the
completion log’s result count, but do not include any authenticated user
identifier in these log entries.
- Line 140: Update the async route around list_saved_prompts_by_user so its
synchronous database work does not execute on the event loop; either convert the
DAL helper and its SQLAlchemy query to async, or offload the existing helper
invocation to the framework’s thread pool, preserving its event-loop-independent
Session handling.
In `@tests/unit/app/endpoints/test_saved_prompts.py`:
- Around line 267-276: Complete the _prompt_row docstring with Google-style
Parameters and Returns sections, documenting each argument and the
SimpleNamespace return value. Keep the helper implementation unchanged and use
the repository’s Parameters heading rather than Args.
- Line 23: Update the MOCK_LIST_AUTH module constant annotation to use
Final[AuthTuple], preserving its existing tuple value and type.
In `@tests/unit/models/README.md`:
- Around line 12-13: Add a blank line between the
test_saved_prompts_list_response.py heading and its descriptive text in the
README, preserving the existing heading and content.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: b89866aa-ad60-4ea1-b6c7-3ac856a7e8ba
📒 Files selected for processing (13)
docs/auth/authorization.mddocs/devel_doc/ARCHITECTURE.mddocs/devel_doc/openapi.jsonsrc/app/endpoints/saved_prompts.pysrc/models/api/responses/successful/README.mdsrc/models/api/responses/successful/__init__.pysrc/models/api/responses/successful/saved_prompts.pysrc/models/config.pytests/unit/app/endpoints/README.mdtests/unit/app/endpoints/test_saved_prompts.pytests/unit/models/README.mdtests/unit/models/test_saved_prompts_list_response.pytests/unit/utils/test_saved_prompts.py
📜 Review details
⏰ Context from checks skipped due to timeout. (14)
- GitHub Check: build-pr
- GitHub Check: integration_tests (3.12)
- GitHub Check: unit_tests (3.13)
- GitHub Check: unit_tests (3.12)
- GitHub Check: integration_tests (3.13)
- GitHub Check: Pylinter
- GitHub Check: E2E: server mode / ci / group 3
- GitHub Check: E2E: library mode / ci / group 3
- GitHub Check: E2E: library mode / ci / group 1
- GitHub Check: E2E: server mode / ci / group 1
- GitHub Check: E2E: server mode / ci / group 2
- GitHub Check: E2E: library mode / ci / group 2
- GitHub Check: E2E Tests for Lightspeed Evaluation job
- GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-0-7-on-pull-request
🧰 Additional context used
📓 Path-based instructions (5)
**/*
📄 CodeRabbit inference engine (Custom checks)
**/*: Flag meaningful O(n^2)+ algorithms on non-trivial inputs, including handlers and Kubernetes list operations.
Flag N+1 patterns that list items and then query once per item, including Kubernetes API and database access.
Flag expensive work inside loops, including API calls, JSON parsing, and regex compilation.
Flag unbounded growth in caches, watchers, or buffers when eviction or limits are missing.
Flag missing pagination or limits on list operations and API endpoints.
Flag secrets or tokens logged in plaintext or hardcoded in source.
Flag API endpoints missing authentication or authorization.
Flag injection vulnerabilities, including SQL injection, command injection, and path traversal.
Flag sensitive data leaked in API responses, WebSocket messages, or logs.
Flag Kubernetes Secrets and Red Hat secrets missing OwnerReferences.Never commit secrets or keys; use environment variables for sensitive data.
Files:
docs/devel_doc/ARCHITECTURE.mdtests/unit/models/README.mdtests/unit/app/endpoints/README.mddocs/auth/authorization.mdsrc/models/api/responses/successful/__init__.pytests/unit/utils/test_saved_prompts.pysrc/models/api/responses/successful/README.mdsrc/models/config.pytests/unit/models/test_saved_prompts_list_response.pydocs/devel_doc/openapi.jsonsrc/models/api/responses/successful/saved_prompts.pysrc/app/endpoints/saved_prompts.pytests/unit/app/endpoints/test_saved_prompts.py
**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
**/*.py: Use absolute imports for internal Python modules.
All modules must begin with descriptive docstrings; package__init__.pyfiles must contain brief package descriptions.
Uselogger = get_logger(__name__)fromlog.pyfor module logging.
UseFinal[type]type hints for constants and keep shared constants in the centralconstants.pymodule with descriptive comments.
Functions must have complete parameter and return type annotations, descriptive snake_case action-oriented names, and docstrings.
Use modern union syntax such asstr | int,Optional[Type]for optional values, andtyping_extensions.Selffor model validators.
Avoid modifying input parameters in place; return a new data structure instead.
Useasync deffor I/O operations and external API calls.
HandleAPIConnectionErrorfrom Llama Stack integrations.
All classes must have descriptive docstrings, PascalCase descriptive names, complete attribute annotations, and specific types instead ofAny.
UseConfigurationBasefor configuration Pydantic models andBaseModelfor other data models.
Use ABC interfaces with@abstractmethoddecorators for abstract classes.
Use@model_validatorand@field_validatorfor custom Pydantic model validation.
Follow Google Python docstring conventions, includingParameters,Returns,Raises, andAttributessections when applicable.
Useuv runfor project commands, including formatting, verification, and tests.
Files:
src/models/api/responses/successful/__init__.pytests/unit/utils/test_saved_prompts.pysrc/models/config.pytests/unit/models/test_saved_prompts_list_response.pysrc/models/api/responses/successful/saved_prompts.pysrc/app/endpoints/saved_prompts.pytests/unit/app/endpoints/test_saved_prompts.py
src/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
Configuration models must extend
ConfigurationBase, whoseextrasetting must be"forbid"to reject unknown fields; use types such asOptional[FilePath],PositiveInt, andSecretStr.
Files:
src/models/api/responses/successful/__init__.pysrc/models/config.pysrc/models/api/responses/successful/saved_prompts.pysrc/app/endpoints/saved_prompts.py
tests/unit/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
tests/unit/**/*.py: Use pytest for unit tests; do not use unittest. Put shared fixtures inconftest.py, usepytest-mockfor mocking, and mark asynchronous tests withpytest.mark.asyncio.
Unit tests must provide at least 60% coverage.
Files:
tests/unit/utils/test_saved_prompts.pytests/unit/models/test_saved_prompts_list_response.pytests/unit/app/endpoints/test_saved_prompts.py
src/app/endpoints/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
Use FastAPI
HTTPExceptionwith appropriate status codes for API endpoint errors.
Files:
src/app/endpoints/saved_prompts.py
🧠 Learnings (7)
📚 Learning: 2026-01-12T10:58:40.230Z
Learnt from: blublinsky
Repo: lightspeed-core/lightspeed-stack PR: 972
File: src/models/config.py:459-513
Timestamp: 2026-01-12T10:58:40.230Z
Learning: In lightspeed-core/lightspeed-stack, for Python files under src/models, when a user claims a fix is done but the issue persists, verify the current code state before accepting the fix. Steps: review the diff, fetch the latest changes, run relevant tests, reproduce the issue, search the codebase for lingering references to the original problem, confirm the fix is applied and not undone by subsequent commits, and validate with local checks to ensure the issue is resolved.
Applied to files:
src/models/api/responses/successful/__init__.pysrc/models/config.pysrc/models/api/responses/successful/saved_prompts.py
📚 Learning: 2026-02-25T07:46:33.545Z
Learnt from: asimurka
Repo: lightspeed-core/lightspeed-stack PR: 1211
File: src/models/responses.py:8-16
Timestamp: 2026-02-25T07:46:33.545Z
Learning: In the Python codebase, requests.py should use OpenAIResponseInputTool as Tool while responses.py uses OpenAIResponseTool as Tool. This difference is intentional due to differing schemas for input vs output tools in llama-stack-api. Apply this distinction consistently to other models under src/models (e.g., ensure request-related tools use the InputTool variant and response-related tools use the ResponseTool variant). If adding new tools, choose the corresponding InputTool or Tool class based on whether the tool represents input or output, and document the rationale in code comments.
Applied to files:
src/models/api/responses/successful/__init__.pysrc/models/config.pysrc/models/api/responses/successful/saved_prompts.py
📚 Learning: 2026-06-24T13:45:37.249Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 1971
File: src/utils/markdown_repair.py:31-36
Timestamp: 2026-06-24T13:45:37.249Z
Learning: In the lightspeed-stack repository, docstrings must use the section header name "Parameters:" (not "Args:") for function arguments, even if the project references Google Python docstring conventions. Ensure docstrings follow the project’s established "Parameters:" header format for any documented function parameters.
Applied to files:
src/models/api/responses/successful/__init__.pytests/unit/utils/test_saved_prompts.pysrc/models/config.pytests/unit/models/test_saved_prompts_list_response.pysrc/models/api/responses/successful/saved_prompts.pysrc/app/endpoints/saved_prompts.pytests/unit/app/endpoints/test_saved_prompts.py
📚 Learning: 2026-07-06T15:26:18.398Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 2071
File: src/models/config.py:2416-2422
Timestamp: 2026-07-06T15:26:18.398Z
Learning: In this repo’s Python code under src/**, don’t treat differences in string concatenation style as a style inconsistency when Black has effectively forced (or made clearer) use of explicit `+` string concatenation in multi-line logger/string expressions. If adjacent-literal implicit concatenation is avoided/changed specifically to accommodate Black’s formatting in these call sites, accept the `+` usage and don’t recommend converting it solely for consistency with nearby blocks that use implicit concatenation.
Applied to files:
src/models/api/responses/successful/__init__.pysrc/models/config.pysrc/models/api/responses/successful/saved_prompts.pysrc/app/endpoints/saved_prompts.py
📚 Learning: 2026-07-17T19:25:05.325Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 2166
File: src/utils/saved_prompts.py:129-157
Timestamp: 2026-07-17T19:25:05.325Z
Learning: For any endpoint that handles saved prompts and calls `src/utils/saved_prompts.py::create_saved_prompt`, treat the endpoint as the validation boundary. Before calling `create_saved_prompt`, validate the incoming saved-prompt name and content, specifically using `validate_saved_prompt_name` and then persist (store) the normalized value it returns. Do not call `create_saved_prompt` with unvalidated/raw name/content.
Applied to files:
src/models/api/responses/successful/__init__.pysrc/models/config.pysrc/models/api/responses/successful/saved_prompts.pysrc/app/endpoints/saved_prompts.py
📚 Learning: 2026-07-21T11:10:05.060Z
Learnt from: are-ces
Repo: lightspeed-core/lightspeed-stack PR: 2162
File: src/a2a_client/__init__.py:3-9
Timestamp: 2026-07-21T11:10:05.060Z
Learning: In this repository, it is acceptable for Python package `__init__.py` files to contain functional code (not only docstrings/metadata) and to perform package-level re-exports. Do not flag `__init__.py` solely for containing imports or other logic used to re-export symbols; this is allowed when it’s implemented via imports and `__all__` (or otherwise clearly intended to define the package’s public API).
Applied to files:
src/models/api/responses/successful/__init__.py
📚 Learning: 2026-04-06T20:18:07.852Z
Learnt from: major
Repo: lightspeed-core/lightspeed-stack PR: 1463
File: src/app/endpoints/rlsapi_v1.py:266-271
Timestamp: 2026-04-06T20:18:07.852Z
Learning: In the lightspeed-stack codebase, within `src/app/endpoints/` inference/MCP endpoints, treat `tools: Optional[list[Any]]` in MCP tool definitions as an intentional, consistent typing pattern (used across `query`, `responses`, `streaming_query`, `rlsapi_v1`). Do not raise or suggest this as a typing issue during code review; changing it in isolation could break endpoint typing consistency across the codebase.
Applied to files:
src/app/endpoints/saved_prompts.py
🪛 markdownlint-cli2 (0.23.0)
tests/unit/models/README.md
[warning] 12-12: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
🔇 Additional comments (13)
src/models/config.py (1)
1310-1312: LGTM!tests/unit/app/endpoints/README.md (1)
70-70: LGTM!tests/unit/utils/test_saved_prompts.py (1)
320-320: LGTM!Also applies to: 339-356
docs/auth/authorization.md (1)
114-114: LGTM!docs/devel_doc/ARCHITECTURE.md (1)
203-205: LGTM!src/models/api/responses/successful/saved_prompts.py (1)
1-3: LGTM!Also applies to: 49-99, 102-132
src/models/api/responses/successful/__init__.py (1)
52-56: LGTM!Also applies to: 97-99
src/models/api/responses/successful/README.md (1)
40-40: LGTM!docs/devel_doc/openapi.json (4)
7097-7253: LGTM!
11186-11187: LGTM!
19603-19668: LGTM!
19760-19794: LGTM!tests/unit/models/test_saved_prompts_list_response.py (1)
1-75: LGTM!
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tests/unit/app/endpoints/test_saved_prompts.py (2)
485-504: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winCover the list handler’s database-error branch.
Add a test that makes
list_saved_prompts_by_userraiseSQLAlchemyErrorand asserts the handler returns HTTP 500 with the database-error response, matching the explicit error path insrc/app/endpoints/saved_prompts.py.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/app/endpoints/test_saved_prompts.py` around lines 485 - 504, Add an async test alongside test_list_saved_prompts_configuration_not_loaded that patches list_saved_prompts_by_user to raise SQLAlchemyError, invokes list_saved_prompts_handler with the existing authorization and request fixtures, and asserts HTTP 500 plus the expected database-error response details from the handler’s explicit exception branch.
399-451: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winExercise authorization through FastAPI’s dependency wiring.
Direct handler calls invoke
assertionswithout FastAPI dependency dispatch, so these “action used/forbidden” tests do not exercise the actual route authorization path. UseTestClient/ASGI requests, or invoke the authorization dependency/wrapping behavior directly rather than the inner handlers at lines 399-451, 595-629, 764-789, 958-984, and 1036-1060.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/app/endpoints/test_saved_prompts.py` around lines 399 - 451, Update the saved-prompts authorization tests, including test_list_saved_prompts_uses_manage_saved_prompts_action and test_list_saved_prompts_forbidden_without_action, to exercise FastAPI dependency wiring through TestClient/ASGI requests or the authorization wrapper/dependency itself instead of calling list_saved_prompts_handler directly. Apply the same approach to the corresponding tests at the referenced ranges, preserving assertions for the required action and 403 response.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/devel_doc/openapi.json`:
- Around line 7384-7455: The saved-prompts OpenAPI responses use shared error
examples and include an invalid DELETE validation response. In the saved-prompts
endpoint definitions in src/app/endpoints/saved_prompts.py, add
endpoint-specific examples for the 409/422 responses and DELETE 400/404
responses, remove DELETE’s saved-prompt 422 HTTPValidationError response, then
regenerate docs/devel_doc/openapi.json; update both affected generated sections
at docs/devel_doc/openapi.json lines 7384-7455 and 7510-7717.
In `@src/models/api/requests/README.md`:
- Around line 30-31: Insert a blank line between the saved_prompts.py heading
and its descriptive text to satisfy the Markdown heading-spacing rule.
---
Outside diff comments:
In `@tests/unit/app/endpoints/test_saved_prompts.py`:
- Around line 485-504: Add an async test alongside
test_list_saved_prompts_configuration_not_loaded that patches
list_saved_prompts_by_user to raise SQLAlchemyError, invokes
list_saved_prompts_handler with the existing authorization and request fixtures,
and asserts HTTP 500 plus the expected database-error response details from the
handler’s explicit exception branch.
- Around line 399-451: Update the saved-prompts authorization tests, including
test_list_saved_prompts_uses_manage_saved_prompts_action and
test_list_saved_prompts_forbidden_without_action, to exercise FastAPI dependency
wiring through TestClient/ASGI requests or the authorization wrapper/dependency
itself instead of calling list_saved_prompts_handler directly. Apply the same
approach to the corresponding tests at the referenced ranges, preserving
assertions for the required action and 403 response.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: e55830af-bf73-4b5c-a1b8-1b119ce7d49f
📒 Files selected for processing (11)
docs/auth/authorization.mddocs/devel_doc/ARCHITECTURE.mddocs/devel_doc/openapi.jsonsrc/app/endpoints/saved_prompts.pysrc/models/api/requests/README.mdsrc/models/api/requests/__init__.pysrc/models/api/requests/saved_prompts.pysrc/models/config.pytests/integration/test_openapi_json.pytests/unit/app/endpoints/test_saved_prompts.pytests/unit/models/README.md
📜 Review details
⏰ Context from checks skipped due to timeout. (14)
- GitHub Check: unit_tests (3.12)
- GitHub Check: unit_tests (3.13)
- GitHub Check: build-pr
- GitHub Check: Pylinter
- GitHub Check: integration_tests (3.12)
- GitHub Check: integration_tests (3.13)
- GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-0-7-on-pull-request
- GitHub Check: E2E: library mode / ci / group 1
- GitHub Check: E2E: server mode / ci / group 1
- GitHub Check: E2E: library mode / ci / group 2
- GitHub Check: E2E: library mode / ci / group 3
- GitHub Check: E2E: server mode / ci / group 2
- GitHub Check: E2E: server mode / ci / group 3
- GitHub Check: E2E Tests for Lightspeed Evaluation job
🧰 Additional context used
📓 Path-based instructions (7)
**/*
📄 CodeRabbit inference engine (Custom checks)
**/*: Flag meaningful O(n^2)+ algorithms on non-trivial inputs, including handlers and Kubernetes list operations.
Flag N+1 patterns that list items and then query once per item, including Kubernetes API and database access.
Flag expensive work inside loops, including API calls, JSON parsing, and regex compilation.
Flag unbounded growth in caches, watchers, or buffers when eviction or limits are missing.
Flag missing pagination or limits on list operations and API endpoints.
Flag secrets or tokens logged in plaintext or hardcoded in source.
Flag API endpoints missing authentication or authorization.
Flag injection vulnerabilities, including SQL injection, command injection, and path traversal.
Flag sensitive data leaked in API responses, WebSocket messages, or logs.
Flag Kubernetes Secrets and Red Hat secrets missing OwnerReferences.
Files:
src/models/api/requests/__init__.pysrc/models/api/requests/README.mdtests/unit/models/README.mdsrc/models/api/requests/saved_prompts.pydocs/devel_doc/ARCHITECTURE.mddocs/auth/authorization.mdtests/integration/test_openapi_json.pysrc/models/config.pydocs/devel_doc/openapi.jsonsrc/app/endpoints/saved_prompts.pytests/unit/app/endpoints/test_saved_prompts.py
**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
**/*.py: Use absolute imports for internal Python modules.
All modules must begin with descriptive docstrings explaining their purpose.
Uselogger = get_logger(__name__)fromlog.pyfor module logging.
Use complete type annotations for function parameters and return types.
Use modern union syntax such asstr | int; useOptional[Type]for optional values.
Usetyping_extensions.Selffor model validators.
Functions must use descriptive, action-oriented snake_case names such asget_,validate_, andcheck_.
Avoid modifying mutable parameters in place; return a new data structure instead.
Useasync deffor I/O operations and external API calls.
HandleAPIConnectionErrorfrom Llama Stack.
All classes must have descriptive docstrings and complete type annotations for class attributes; use specific types instead ofAny.
Use PascalCase for classes and descriptive standard suffixes such asConfiguration,Error/Exception,Resolver, andInterface.
Use ABC and@abstractmethodfor abstract interfaces.
Follow Google Python docstring conventions; document all modules, classes, and functions, includingParameters,Returns,Raises, andAttributessections as applicable.
Never commit secrets or keys; use environment variables for sensitive data.
Files:
src/models/api/requests/__init__.pysrc/models/api/requests/saved_prompts.pytests/integration/test_openapi_json.pysrc/models/config.pysrc/app/endpoints/saved_prompts.pytests/unit/app/endpoints/test_saved_prompts.py
**/__init__.py
📄 CodeRabbit inference engine (AGENTS.md)
Package
__init__.pyfiles must contain brief package descriptions.
Files:
src/models/api/requests/__init__.py
src/models/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
src/models/**/*.py: ExtendConfigurationBasefor configuration models andBaseModelfor data models.
Use@model_validatorand@field_validatorfor Pydantic model validation.
Files:
src/models/api/requests/__init__.pysrc/models/api/requests/saved_prompts.pysrc/models/config.py
tests/integration/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
Use pytest for all integration tests; do not use unittest.
Files:
tests/integration/test_openapi_json.py
src/app/endpoints/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
Use FastAPI
HTTPExceptionwith appropriate status codes for API endpoints.
Files:
src/app/endpoints/saved_prompts.py
tests/unit/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
tests/unit/**/*.py: Use pytest for all unit tests; do not use unittest.
Useconftest.pyfor shared fixtures,pytest-mockforAsyncMockobjects, andpytest.mark.asynciofor asynchronous tests.
Files:
tests/unit/app/endpoints/test_saved_prompts.py
🧠 Learnings (7)
📚 Learning: 2026-01-12T10:58:40.230Z
Learnt from: blublinsky
Repo: lightspeed-core/lightspeed-stack PR: 972
File: src/models/config.py:459-513
Timestamp: 2026-01-12T10:58:40.230Z
Learning: In lightspeed-core/lightspeed-stack, for Python files under src/models, when a user claims a fix is done but the issue persists, verify the current code state before accepting the fix. Steps: review the diff, fetch the latest changes, run relevant tests, reproduce the issue, search the codebase for lingering references to the original problem, confirm the fix is applied and not undone by subsequent commits, and validate with local checks to ensure the issue is resolved.
Applied to files:
src/models/api/requests/__init__.pysrc/models/api/requests/saved_prompts.pysrc/models/config.py
📚 Learning: 2026-02-25T07:46:33.545Z
Learnt from: asimurka
Repo: lightspeed-core/lightspeed-stack PR: 1211
File: src/models/responses.py:8-16
Timestamp: 2026-02-25T07:46:33.545Z
Learning: In the Python codebase, requests.py should use OpenAIResponseInputTool as Tool while responses.py uses OpenAIResponseTool as Tool. This difference is intentional due to differing schemas for input vs output tools in llama-stack-api. Apply this distinction consistently to other models under src/models (e.g., ensure request-related tools use the InputTool variant and response-related tools use the ResponseTool variant). If adding new tools, choose the corresponding InputTool or Tool class based on whether the tool represents input or output, and document the rationale in code comments.
Applied to files:
src/models/api/requests/__init__.pysrc/models/api/requests/saved_prompts.pysrc/models/config.py
📚 Learning: 2026-06-24T13:45:37.249Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 1971
File: src/utils/markdown_repair.py:31-36
Timestamp: 2026-06-24T13:45:37.249Z
Learning: In the lightspeed-stack repository, docstrings must use the section header name "Parameters:" (not "Args:") for function arguments, even if the project references Google Python docstring conventions. Ensure docstrings follow the project’s established "Parameters:" header format for any documented function parameters.
Applied to files:
src/models/api/requests/__init__.pysrc/models/api/requests/saved_prompts.pytests/integration/test_openapi_json.pysrc/models/config.pysrc/app/endpoints/saved_prompts.pytests/unit/app/endpoints/test_saved_prompts.py
📚 Learning: 2026-07-06T15:26:18.398Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 2071
File: src/models/config.py:2416-2422
Timestamp: 2026-07-06T15:26:18.398Z
Learning: In this repo’s Python code under src/**, don’t treat differences in string concatenation style as a style inconsistency when Black has effectively forced (or made clearer) use of explicit `+` string concatenation in multi-line logger/string expressions. If adjacent-literal implicit concatenation is avoided/changed specifically to accommodate Black’s formatting in these call sites, accept the `+` usage and don’t recommend converting it solely for consistency with nearby blocks that use implicit concatenation.
Applied to files:
src/models/api/requests/__init__.pysrc/models/api/requests/saved_prompts.pysrc/models/config.pysrc/app/endpoints/saved_prompts.py
📚 Learning: 2026-07-17T19:25:05.325Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 2166
File: src/utils/saved_prompts.py:129-157
Timestamp: 2026-07-17T19:25:05.325Z
Learning: For any endpoint that handles saved prompts and calls `src/utils/saved_prompts.py::create_saved_prompt`, treat the endpoint as the validation boundary. Before calling `create_saved_prompt`, validate the incoming saved-prompt name and content, specifically using `validate_saved_prompt_name` and then persist (store) the normalized value it returns. Do not call `create_saved_prompt` with unvalidated/raw name/content.
Applied to files:
src/models/api/requests/__init__.pysrc/models/api/requests/saved_prompts.pysrc/models/config.pysrc/app/endpoints/saved_prompts.py
📚 Learning: 2026-07-21T11:10:05.060Z
Learnt from: are-ces
Repo: lightspeed-core/lightspeed-stack PR: 2162
File: src/a2a_client/__init__.py:3-9
Timestamp: 2026-07-21T11:10:05.060Z
Learning: In this repository, it is acceptable for Python package `__init__.py` files to contain functional code (not only docstrings/metadata) and to perform package-level re-exports. Do not flag `__init__.py` solely for containing imports or other logic used to re-export symbols; this is allowed when it’s implemented via imports and `__all__` (or otherwise clearly intended to define the package’s public API).
Applied to files:
src/models/api/requests/__init__.py
📚 Learning: 2026-04-06T20:18:07.852Z
Learnt from: major
Repo: lightspeed-core/lightspeed-stack PR: 1463
File: src/app/endpoints/rlsapi_v1.py:266-271
Timestamp: 2026-04-06T20:18:07.852Z
Learning: In the lightspeed-stack codebase, within `src/app/endpoints/` inference/MCP endpoints, treat `tools: Optional[list[Any]]` in MCP tool definitions as an intentional, consistent typing pattern (used across `query`, `responses`, `streaming_query`, `rlsapi_v1`). Do not raise or suggest this as a typing issue during code review; changing it in isolation could break endpoint typing consistency across the codebase.
Applied to files:
src/app/endpoints/saved_prompts.py
🪛 markdownlint-cli2 (0.23.0)
src/models/api/requests/README.md
[warning] 30-30: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
🔇 Additional comments (20)
tests/integration/test_openapi_json.py (1)
260-270: LGTM!Also applies to: 376-386
tests/unit/app/endpoints/test_saved_prompts.py (1)
3-45: LGTM!Also applies to: 155-156, 257-396, 454-483, 505-594, 632-763, 792-955, 987-1035, 1063-1091
tests/unit/models/README.md (1)
12-14: LGTM!src/models/config.py (2)
1310-1311: LGTM!
2385-2418: LGTM!docs/auth/authorization.md (1)
103-114: LGTM!docs/devel_doc/ARCHITECTURE.md (1)
203-205: LGTM!src/models/api/requests/saved_prompts.py (1)
1-38: LGTM!src/models/api/requests/__init__.py (1)
18-18: LGTM!Also applies to: 41-41
docs/devel_doc/openapi.json (5)
6940-6940: LGTM!
7098-7251: LGTM!
11692-11692: LGTM!
20108-20207: LGTM!
20255-20317: LGTM!src/app/endpoints/saved_prompts.py (6)
5-67: LGTM!
87-108: LGTM!
133-150: LGTM!
153-195: LGTM!
289-357: LGTM!
246-266: 🗄️ Data Integrity & IntegrationNo change needed for content persistence.
validate_saved_prompt_contentvalidates in place and returnsNone; it does not normalize persisted content.> Likely an incorrect or invalid review comment.
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Description
Adds authenticated CRUD-style saved prompts APIs for the current user:
GET /v1/saved-prompts— list saved prompts (newest first)POST /v1/saved-prompts— create a saved prompt (name+content)DELETE /v1/saved-prompts/{prompt_id}— delete an owned saved prompt (204; missing or non-owned → 404 to avoid probing)MANAGE_SAVED_PROMPTSauthorization for list/create/deleteGET /v1/saved-prompts/config/saved_promptsYAML sectionType of change
Tools used to create PR
Related Tickets & Documents
Checklist before requesting a review
Testing
tests/unit/app/endpoints/test_saved_prompts.pyfor list/create/delete (authz, validation, ownership scoping, error mapping).id→ DELETE → 204; non-owner/user_idmismatch → 404;saved_prompts.max_prompts_per_userenforced after config reload.