chore: Add ai safety prompt to system prompt - #823
Conversation
WalkthroughAdds a new AI safety Jinja2 partial and includes it in selected prompt templates. Updates kubernetes_workload_ask and _general_instructions to include the safety partial. Introduces tests ensuring the safety content is included in rendered prompts and that the safety template exists and renders correctly. Changes
Sequence Diagram(s)sequenceDiagram
participant R as Renderer
participant T as Main Template (generic/investigation/...)
participant G as _general_instructions.jinja2
participant S as _ai_safety.jinja2
R->>T: Render template
T->>G: {% include "_general_instructions.jinja2" %}
G->>S: {% include "_ai_safety.jinja2" %}
S-->>G: Safety sections
G-->>T: General instructions + Safety
T-->>R: Final prompt output
sequenceDiagram
participant R as Renderer
participant K as kubernetes_workload_ask.jinja2
participant S as _ai_safety.jinja2
R->>K: Render template
K->>S: {% include "_ai_safety.jinja2" %}
S-->>K: Safety sections
K-->>R: Final prompt output
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes ✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
c26f4c4 to
4e35d79
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
tests/test_ai_safety_prompt.py (3)
20-31: Add type hints to satisfy repository typing standardsPer repo guidelines, Python files should include type hints. Add annotations to the test method signature and the local context variable.
Apply this diff:
- def test_ai_safety_prompt_included(self, template_path): + def test_ai_safety_prompt_included(self, template_path: str) -> None: @@ - context = { + context: dict[str, object] = { "toolsets": [], "cluster_name": "test-cluster", "issue": {"source_type": "test"}, # for investigation template "investigation": "test investigation", # for issue conversation template "tools_called_for_investigation": [], # for issue conversation template "sections": {}, # for investigation template output format }
66-77: Type hints for the second test functionAdd a return type for compliance with typing rules.
Apply this diff:
-def test_ai_safety_template_exists(): +def test_ai_safety_template_exists() -> None:
32-64: Optional: reduce repetition by asserting over a list of expected substringsFactor expected snippets into a list and loop for assertions to make the test more maintainable if sections evolve.
Apply this diff:
- # Check that key AI safety sections are present - assert ( - "# Safety & Guardrails" in rendered - ), f"AI safety header missing from {template_path}" - assert ( - "## Content Harms" in rendered - ), f"Content Harms section missing from {template_path}" - assert ( - "## Jailbreaks – UPIA" in rendered - ), f"UPIA section missing from {template_path}" - assert ( - "## Jailbreaks – XPIA" in rendered - ), f"XPIA section missing from {template_path}" - assert ( - "## IP / Third-Party Content Regurgitation" in rendered - ), f"IP section missing from {template_path}" - assert ( - "## Ungrounded Content" in rendered - ), f"Ungrounded Content section missing from {template_path}" - - # Check for key safety phrases - assert ( - "non-negotiable" in rendered - ), f"Non-negotiable clause missing from {template_path}" - assert ( - "copyright laws" in rendered - ), f"Copyright clause missing from {template_path}" - assert ( - "physical or emotional harm" in rendered - ), f"Harm prevention clause missing from {template_path}" + expected_snippets = [ + "# Safety & Guardrails", + "## Content Harms", + "## Jailbreaks – UPIA", + "## Jailbreaks – XPIA", + "## IP / Third-Party Content Regurgitation", + "## Ungrounded Content", + "non-negotiable", + "copyright laws", + "physical or emotional harm", + ] + for snippet in expected_snippets: + assert snippet in rendered, f"Missing '{snippet}' in {template_path}"holmes/plugins/prompts/_ai_safety.jinja2 (1)
37-44: Align “Ungrounded Content” with Holmes’ tool-first workflowTo reduce ambiguity and align with the rest of the prompts (which instruct to use tools first), explicitly reference running Holmes tools/integrations when seeking factual info.
Apply this diff:
-When the user is seeking factual or current information, you must: -- Perform searches on **[relevant documents]** first (e.g., internal tools, external knowledge sources) +When the user is seeking factual or current information, you must: +- Run Holmes tools/integrations to search relevant documents and telemetry first (e.g., logs, traces, metrics, runbooks, external sources) - Base factual statements **only** on what is retrieved - Avoid vague, speculative, or hallucinated responses - Do not supplement with internal knowledge if the returned sources are incomplete You may add relevant, logically connected details from the search to ensure a thorough and comprehensive answer—**but not go beyond the facts provided**.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
holmes/plugins/prompts/_ai_safety.jinja2(1 hunks)holmes/plugins/prompts/generic_ask.jinja2(1 hunks)holmes/plugins/prompts/generic_ask_conversation.jinja2(1 hunks)holmes/plugins/prompts/generic_ask_for_issue_conversation.jinja2(1 hunks)holmes/plugins/prompts/generic_investigation.jinja2(1 hunks)holmes/plugins/prompts/kubernetes_workload_ask.jinja2(1 hunks)tests/test_ai_safety_prompt.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
holmes/plugins/prompts/**/*.jinja2
📄 CodeRabbit Inference Engine (CLAUDE.md)
Prompts must be located at holmes/plugins/prompts/{name}.jinja2
Files:
holmes/plugins/prompts/kubernetes_workload_ask.jinja2holmes/plugins/prompts/generic_ask.jinja2holmes/plugins/prompts/_ai_safety.jinja2holmes/plugins/prompts/generic_investigation.jinja2holmes/plugins/prompts/generic_ask_conversation.jinja2holmes/plugins/prompts/generic_ask_for_issue_conversation.jinja2
**/*.py
📄 CodeRabbit Inference Engine (CLAUDE.md)
**/*.py: ALWAYS place Python imports at the top of the file, not inside functions or methods
Use Ruff for formatting and linting (configured in pyproject.toml)
Type hints required (mypy configuration in pyproject.toml)
Pre-commit hooks enforce quality checks
Don't add convenience logs that give away the problem
Don't write logs that directly state the issue
Ensure historical timestamps are properly handled in logs (especially with Loki)
Files:
tests/test_ai_safety_prompt.py
tests/**
📄 CodeRabbit Inference Engine (CLAUDE.md)
Tests must match source structure under tests/
Files:
tests/test_ai_safety_prompt.py
🧠 Learnings (1)
📚 Learning: 2025-08-10T06:02:54.321Z
Learnt from: CR
PR: robusta-dev/holmesgpt#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-10T06:02:54.321Z
Learning: Applies to holmes/plugins/prompts/**/*.jinja2 : Prompts must be located at holmes/plugins/prompts/{name}.jinja2
Applied to files:
holmes/plugins/prompts/kubernetes_workload_ask.jinja2holmes/plugins/prompts/generic_ask.jinja2holmes/plugins/prompts/_ai_safety.jinja2holmes/plugins/prompts/generic_ask_conversation.jinja2tests/test_ai_safety_prompt.py
🧬 Code Graph Analysis (1)
tests/test_ai_safety_prompt.py (1)
holmes/plugins/prompts/__init__.py (1)
load_and_render_prompt(27-48)
🔇 Additional comments (8)
holmes/plugins/prompts/generic_investigation.jinja2 (1)
8-8: AI safety partial correctly included in system promptIncluding the AI safety partial right after the current date/time block is consistent with the other templates and maintains the bullet formatting. Looks good.
holmes/plugins/prompts/generic_ask.jinja2 (1)
9-10: AI safety partial inclusion looks correct and well placedPlacement after the date/time include is consistent across templates, and spacing is fine. No issues spotted.
holmes/plugins/prompts/generic_ask_for_issue_conversation.jinja2 (1)
8-9: Consistent inclusion of AI safety partialRight after the date/time include and before the rest of the instructions; consistent with other templates. Good to go.
holmes/plugins/prompts/generic_ask_conversation.jinja2 (1)
9-10: AI safety partial inclusion is correctPlacement and formatting align with the rest of the templates. No further changes needed.
holmes/plugins/prompts/kubernetes_workload_ask.jinja2 (1)
9-10: AI safety partial included in the right locationInserted right after date/time and before Global Instructions, which is an appropriate place. Looks good.
tests/test_ai_safety_prompt.py (2)
10-19: Good coverage: parametrized test ensures safety partial inclusion across main templatesParametrizing over the main system prompts and asserting for key sections/phrases provides solid coverage for this change. Nice work.
66-69: Builtin loader supports leading-underscore templates
Theload_promptfunction simply strips thebuiltin://prefix and joins the remaining filename (underscores and all) with the prompts directory. The file_ai_safety.jinja2is present underholmes/plugins/prompts, so the test will pass without modification.• holmes/plugins/prompts/init.py:
- Lines 17–18: path = os.path.join(THIS_DIR, prompt[len("builtin://"):])
• File exists at:holmes/plugins/prompts/_ai_safety.jinja2holmes/plugins/prompts/_ai_safety.jinja2 (1)
1-16: Solid, pragmatic safety guidanceClear, enforceable rules with explicit refusal guidance and confidentiality. Nicely scoped and consistent with the system’s constraints.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
holmes/plugins/prompts/_general_instructions.jinja2 (1)
1-2: Action Required: Manually Confirm No Duplicate AI Safety IncludesI couldn’t automatically detect any templates that include both
_ai_safety.jinja2and_general_instructions.jinja2. Please manually verify that no template underholmes/plugins/prompts:
- Directly includes
_ai_safety.jinja2- And also includes
_general_instructions.jinja2If a template already pulls in the safety block via
_general_instructions.jinja2, remove its direct_ai_safety.jinja2include to avoid rendering it twice.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
holmes/plugins/prompts/_general_instructions.jinja2(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
holmes/plugins/prompts/**/*.jinja2
📄 CodeRabbit Inference Engine (CLAUDE.md)
Prompts must be located at holmes/plugins/prompts/{name}.jinja2
Files:
holmes/plugins/prompts/_general_instructions.jinja2
🧠 Learnings (1)
📚 Learning: 2025-08-10T06:02:54.321Z
Learnt from: CR
PR: robusta-dev/holmesgpt#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-10T06:02:54.321Z
Learning: Applies to holmes/plugins/prompts/**/*.jinja2 : Prompts must be located at holmes/plugins/prompts/{name}.jinja2
Applied to files:
holmes/plugins/prompts/_general_instructions.jinja2
⏰ 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: Pre-commit checks
🔇 Additional comments (1)
holmes/plugins/prompts/_general_instructions.jinja2 (1)
1-2: Include placement and path look correct; aligns with prompts location policy.Including the AI safety partial at the very top is a sane default and keeps safety guidance centralized. Naming and relative include style match existing partials (e.g., _toolsets_instructions, _permission_errors) and comply with the prompts location guideline for holmes/plugins/prompts/**/*.jinja2.
mainred
left a comment
There was a problem hiding this comment.
Looks good to me. let Robusta team check if there's any missing.
chore: Add ai safety prompt to system prompt