feat(platform): enforce mandatory governance system prompt#1257
Conversation
…nt generations Add system prompt governance policy that prepends/appends mandatory text to agent instructions across both the agent chat and OpenAI-compatible endpoints. Includes settings navigation link, backend query, and en/de i18n strings. Also simplifies the convex dev script flags.
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
📝 WalkthroughWalkthroughThis PR introduces a governance feature enabling organizations to set mandatory system prompt prefixes and suffixes. Changes include a new "Governance" settings navigation tab, a Convex query ( Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@services/platform/convex/openai_compat/internal_actions.ts`:
- Around line 295-311: The governance prompt wrapping logic (checking
systemPromptPolicy, trimming and applying
mandatoryPrefixPrompt/mandatorySuffixPrompt to systemPrompt) is duplicated
between internal_actions.ts and
services/platform/convex/lib/agent_chat/internal_actions.ts; extract that
behavior into a shared helper (e.g., applyMandatoryGovernancePrompts(policy,
systemPrompt): string) and replace the inline blocks that reference
systemPromptPolicy, cfg.mandatoryPrefixPrompt, and cfg.mandatorySuffixPrompt
with calls to this helper so both chat flows use the exact same
trimming/prepend/append semantics and remain synchronized as policy rules
change.
In `@services/platform/messages/de.json`:
- Line 3502: The German translation for the JSON key "suffixDescription"
contains a case error; update its value by replacing "nach die Anweisungen" with
the correct phrase "nach den Anweisungen" so the string becomes "Dieser Text
wird nach den Anweisungen jedes Agents angehängt und kann nicht überschrieben
werden."
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1e041d81-cb0f-4c73-85d4-21db7d8c1ebd
📒 Files selected for processing (7)
services/platform/app/features/settings/components/settings-navigation.tsxservices/platform/convex/governance/internal_queries.tsservices/platform/convex/lib/agent_chat/internal_actions.tsservices/platform/convex/openai_compat/internal_actions.tsservices/platform/messages/de.jsonservices/platform/messages/en.jsonservices/platform/scripts/dev.ts
| // Apply mandatory governance system prompt (non-overridable) | ||
| if ( | ||
| systemPromptPolicy?.enabled !== false && | ||
| isRecord(systemPromptPolicy?.config) | ||
| ) { | ||
| const cfg = systemPromptPolicy.config; | ||
| const prefix = | ||
| typeof cfg.mandatoryPrefixPrompt === 'string' | ||
| ? cfg.mandatoryPrefixPrompt.trim() | ||
| : ''; | ||
| const suffix = | ||
| typeof cfg.mandatorySuffixPrompt === 'string' | ||
| ? cfg.mandatorySuffixPrompt.trim() | ||
| : ''; | ||
| if (prefix) systemPrompt = prefix + '\n\n' + systemPrompt; | ||
| if (suffix) systemPrompt = systemPrompt + '\n\n' + suffix; | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Extract governance prompt wrapping into a shared helper to prevent behavior drift.
The trim/prepend/append logic is duplicated here and in services/platform/convex/lib/agent_chat/internal_actions.ts. Centralizing it in one helper will keep both chat paths behavior-identical as policy rules evolve.
♻️ Suggested direction
- if (
- systemPromptPolicy?.enabled !== false &&
- isRecord(systemPromptPolicy?.config)
- ) {
- const cfg = systemPromptPolicy.config;
- const prefix =
- typeof cfg.mandatoryPrefixPrompt === 'string'
- ? cfg.mandatoryPrefixPrompt.trim()
- : '';
- const suffix =
- typeof cfg.mandatorySuffixPrompt === 'string'
- ? cfg.mandatorySuffixPrompt.trim()
- : '';
- if (prefix) systemPrompt = prefix + '\n\n' + systemPrompt;
- if (suffix) systemPrompt = systemPrompt + '\n\n' + suffix;
- }
+ systemPrompt = applyMandatorySystemPromptPolicy(
+ systemPrompt,
+ systemPromptPolicy,
+ );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@services/platform/convex/openai_compat/internal_actions.ts` around lines 295
- 311, The governance prompt wrapping logic (checking systemPromptPolicy,
trimming and applying mandatoryPrefixPrompt/mandatorySuffixPrompt to
systemPrompt) is duplicated between internal_actions.ts and
services/platform/convex/lib/agent_chat/internal_actions.ts; extract that
behavior into a shared helper (e.g., applyMandatoryGovernancePrompts(policy,
systemPrompt): string) and replace the inline blocks that reference
systemPromptPolicy, cfg.mandatoryPrefixPrompt, and cfg.mandatorySuffixPrompt
with calls to this helper so both chat flows use the exact same
trimming/prepend/append semantics and remain synchronized as policy rules
change.
| "prefixPlaceholder": "Verbindliches Prompt-Präfix eingeben...", | ||
| "suffix": "Suffix (wird nach Agent-Anweisungen angehängt)", | ||
| "suffixLabel": "Verbindliches Suffix", | ||
| "suffixDescription": "Dieser Text wird nach die Anweisungen jedes Agents angehängt und kann nicht überschrieben werden.", |
There was a problem hiding this comment.
Fix German grammar in suffix description.
Line 3502 uses incorrect case: nach die Anweisungen. It should be nach den Anweisungen.
✍️ Proposed text fix
- "suffixDescription": "Dieser Text wird nach die Anweisungen jedes Agents angehängt und kann nicht überschrieben werden.",
+ "suffixDescription": "Dieser Text wird nach den Anweisungen jedes Agents angehängt und kann nicht überschrieben werden.",📝 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.
| "suffixDescription": "Dieser Text wird nach die Anweisungen jedes Agents angehängt und kann nicht überschrieben werden.", | |
| "suffixDescription": "Dieser Text wird nach den Anweisungen jedes Agents angehängt und kann nicht überschrieben werden.", |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@services/platform/messages/de.json` at line 3502, The German translation for
the JSON key "suffixDescription" contains a case error; update its value by
replacing "nach die Anweisungen" with the correct phrase "nach den Anweisungen"
so the string becomes "Dieser Text wird nach den Anweisungen jedes Agents
angehängt und kann nicht überschrieben werden."
Closes #1171
Summary
getSystemPromptPolicyInternal), and en/de i18n strings--local --local-force-upgradeflagsTest plan
Summary by CodeRabbit
Release Notes