Skip to content

RHIDP-14302: add saved prompts database schema#2057

Open
Jdubrick wants to merge 2 commits into
lightspeed-core:mainfrom
Jdubrick:add-saved-prompts-db
Open

RHIDP-14302: add saved prompts database schema#2057
Jdubrick wants to merge 2 commits into
lightspeed-core:mainfrom
Jdubrick:add-saved-prompts-db

Conversation

@Jdubrick

@Jdubrick Jdubrick commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

  • Adds a new table to the db saved_prompts, this will be used in future changes to allow users to save frequently used prompts. This differs from the current llama stack prompt template as:
    • Prompts are user scoped
    • Decoupled from Llama Stack itself
    • Can be persisted alongside conversations and can be stored in postgres alongside conversations

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
  • Benchmarks improvement

Tools used to create PR

Identify any AI code assistants used in this PR (for transparency and review context)

  • Assisted-by: Composer 2.5
  • Generated by: (e.g., tool name and version; N/A if not used)

Related Tickets & Documents

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.

Summary by CodeRabbit

  • New Features

    • Added support for storing users’ saved prompts, including prompt content and automatic created/updated timestamps.
    • Enforced unique prompt names per user to prevent duplicate saved entries.
  • Tests

    • Added unit coverage for the saved prompt model, including schema checks, persistence, timestamp behavior, and duplicate-name validation.
  • Documentation

    • Updated database model documentation to include the new saved prompt model.

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Jdubrick, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c415c603-b223-4d09-80fd-a4c869ced037

📥 Commits

Reviewing files that changed from the base of the PR and between 91b86c0 and ff585db.

📒 Files selected for processing (1)
  • src/models/database/README.md

Walkthrough

This PR adds a new SavedPrompt SQLAlchemy ORM model for persisting user saved prompts, mapped to the saved_prompt table with a unique constraint on (user_id, name), timestamped columns, a README documentation entry, and accompanying unit tests covering schema definition and database operations.

Changes

SavedPrompt Model Addition

Layer / File(s) Summary
SavedPrompt model and README docs
src/models/database/saved_prompts.py, src/models/database/README.md
Defines the SavedPrompt model with id, user_id, name, content, created_at, updated_at columns and a UniqueConstraint("user_id", "name"); adds a README entry documenting the new module.
Unit tests for SavedPrompt
tests/unit/models/database/__init__.py, tests/unit/models/database/test_saved_prompts.py
Adds an in-memory SQLite engine/session fixture, schema-definition tests, and database operation tests (insert/read, uniqueness violation via IntegrityError).

Estimated code review effort: 2 (Simple) | ~12 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant Session
  participant Engine
  participant Database

  Test->>Session: insert SavedPrompt(user_id, name, content)
  Session->>Engine: flush/commit
  Engine->>Database: INSERT into saved_prompt
  Database-->>Engine: enforce UniqueConstraint(user_id, name)
  Engine-->>Session: raise IntegrityError on duplicate
  Test->>Session: db_session.get(SavedPrompt, id)
  Session-->>Test: return row with created_at/updated_at
Loading

Related issues: None specified.

Related PRs: None specified.

Suggested labels: database, models, tests

Suggested reviewers: None specified.

Poem

A rabbit taps its paw with glee,
A new table hops in, wild and free,
saved_prompt rows now safely stay,
Unique per name, come what may,
Tests confirm it, snug and tight —
Timestamps ticking through the night. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a saved prompts database schema.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified 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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/models/database/README.md`:
- Around line 12-13: The README markdown has lint issues from a missing blank
line before the saved_prompts.py heading and a missing trailing newline. Update
the markdown in the README content around the saved_prompts.py section to insert
the required blank line before the heading and ensure the file ends with a
newline.
🪄 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: c6a74e54-fa15-40d9-bf99-c424de45b85c

📥 Commits

Reviewing files that changed from the base of the PR and between d4a978d and 91b86c0.

📒 Files selected for processing (4)
  • src/models/database/README.md
  • src/models/database/saved_prompts.py
  • tests/unit/models/database/__init__.py
  • tests/unit/models/database/test_saved_prompts.py
📜 Review details
⏰ Context from checks skipped due to timeout. (16)
  • GitHub Check: build-pr
  • GitHub Check: Pylinter
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: spectral
  • GitHub Check: integration_tests (3.12)
  • GitHub Check: integration_tests (3.13)
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-0-6-on-pull-request
  • GitHub Check: E2E: server mode / ci / group 2
  • GitHub Check: E2E: library mode / ci / group 3
  • GitHub Check: E2E Tests for Lightspeed Evaluation job
  • GitHub Check: E2E: server mode / ci / group 3
  • GitHub Check: E2E: library mode / ci / group 2
  • GitHub Check: E2E: server mode / ci / group 1
  • GitHub Check: E2E: library mode / ci / group 1
🧰 Additional context used
📓 Path-based instructions (3)
tests/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

tests/**/*.py: Use pytest for all unit and integration tests; do not use unittest
Use pytest.mark.asyncio marker for async tests

Files:

  • tests/unit/models/database/test_saved_prompts.py
  • tests/unit/models/database/__init__.py
src/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.py: Use absolute imports for internal modules: from authentication import get_auth_dependency
Llama Stack imports: Use from llama_stack_client import AsyncLlamaStackClient
Check constants.py for shared constants before defining new ones
All modules must start with descriptive docstrings explaining purpose
Use logger = get_logger(__name__) from log.py for module logging
All functions must have complete type annotations for parameters and return types, use modern syntax (str | int), and include descriptive docstrings
Use snake_case with descriptive, action-oriented names for functions (get_, validate_, check_)
Avoid in-place parameter modification anti-patterns; return new data structures instead of modifying function parameters
Use async def for I/O operations and external API calls
Use standard log levels with clear purposes: debug() for diagnostic info, info() for program execution, warning() for unexpected events, error() for serious problems
All classes must have descriptive docstrings explaining purpose and use PascalCase with standard suffixes: Configuration, Error/Exception, Resolver, Interface
Abstract classes must use ABC with @abstractmethod decorators
Follow Google Python docstring conventions with required sections: Parameters, Returns, Raises, and Attributes for classes

Files:

  • src/models/database/saved_prompts.py
src/models/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Pydantic models must use @model_validator and @field_validator for validation and complete type annotations for all attributes, avoiding Any type

Files:

  • src/models/database/saved_prompts.py
🧠 Learnings (3)
📚 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:

  • tests/unit/models/database/test_saved_prompts.py
  • src/models/database/saved_prompts.py
  • tests/unit/models/database/__init__.py
📚 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/database/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/database/saved_prompts.py
🪛 markdownlint-cli2 (0.22.1)
src/models/database/README.md

[warning] 12-12: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)


[warning] 13-13: Files should end with a single newline character

(MD047, single-trailing-newline)

🔇 Additional comments (4)
src/models/database/saved_prompts.py (2)

1-35: LGTM!


19-19: 🗄️ Data Integrity & Integration

No change needed for SavedPrompt.id.

tests/unit/models/database/__init__.py (1)

1-1: LGTM!

tests/unit/models/database/test_saved_prompts.py (1)

1-147: LGTM!

Comment thread src/models/database/README.md Outdated
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
@Jdubrick

Jdubrick commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

cc @tisnik

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.

1 participant