Bump policy versions and add missing buildErrorResponseV2 analytics metadata#121
Bump policy versions and add missing buildErrorResponseV2 analytics metadata#121Krishanx92 merged 1 commit intowso2:mainfrom
Conversation
WalkthroughGo toolchain updated across 11 policy modules from 1.25.7 to 1.26.1. All policy definitions bumped to v0.9.1. SDK core dependencies updated (some versions upgraded, indirect markers removed). Four guardrail policies enriched with analytics metadata in error responses. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 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 unit tests (beta)
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: 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 `@policies/semantic-prompt-guard/semanticpromptguard.go`:
- Around line 619-622: Update the analytics metadata to use kebab-case for the
guardrail name: find the analyticsMetadata map where "guardrailName" is set
(variable analyticsMetadata in semanticpromptguard.go) and change the value from
"SemanticPromptGuard" to "semantic-prompt-guard" so it matches other guardrails'
naming convention (e.g., "url-guardrail", "word-count-guardrail"). Ensure no
other occurrences of the PascalCase string remain in that map or nearby
logging/analytics emission code.
In `@policies/url-guardrail/urlguardrail.go`:
- Around line 809-812: Remove the added AnalyticsMetadata assignments: delete
the creation/usage of the analyticsMetadata map and any assignments that set
AnalyticsMetadata on policy/v1alpha2.DownstreamResponseModifications and
policy/v1alpha2.ImmediateResponse (the code that assigns analyticsMetadata to
those structs) because v0.1.2 of github.com/wso2/api-platform/sdk/core does not
expose AnalyticsMetadata; revert those changes so the
DownstreamResponseModifications and ImmediateResponse objects are constructed
without an AnalyticsMetadata field, or guard them behind an SDK-version check
until the SDK adds that field.
🪄 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: CHILL
Plan: Pro
Run ID: 6e1c68e8-298e-40cc-9cee-a03aadedd942
⛔ Files ignored due to path filters (9)
policies/api-key-auth/go.sumis excluded by!**/*.sumpolicies/aws-bedrock-guardrail/go.sumis excluded by!**/*.sumpolicies/azure-content-safety-content-moderation/go.sumis excluded by!**/*.sumpolicies/content-length-guardrail/go.sumis excluded by!**/*.sumpolicies/json-schema-guardrail/go.sumis excluded by!**/*.sumpolicies/semantic-prompt-guard/go.sumis excluded by!**/*.sumpolicies/sentence-count-guardrail/go.sumis excluded by!**/*.sumpolicies/url-guardrail/go.sumis excluded by!**/*.sumpolicies/word-count-guardrail/go.sumis excluded by!**/*.sum
📒 Files selected for processing (23)
policies/api-key-auth/go.modpolicies/api-key-auth/policy-definition.yamlpolicies/aws-bedrock-guardrail/go.modpolicies/aws-bedrock-guardrail/policy-definition.yamlpolicies/azure-content-safety-content-moderation/go.modpolicies/azure-content-safety-content-moderation/policy-definition.yamlpolicies/content-length-guardrail/go.modpolicies/content-length-guardrail/policy-definition.yamlpolicies/json-schema-guardrail/go.modpolicies/json-schema-guardrail/policy-definition.yamlpolicies/regex-guardrail/policy-definition.yamlpolicies/semantic-prompt-guard/go.modpolicies/semantic-prompt-guard/policy-definition.yamlpolicies/semantic-prompt-guard/semanticpromptguard.gopolicies/sentence-count-guardrail/go.modpolicies/sentence-count-guardrail/policy-definition.yamlpolicies/sentence-count-guardrail/sentencecountguardrail.gopolicies/url-guardrail/go.modpolicies/url-guardrail/policy-definition.yamlpolicies/url-guardrail/urlguardrail.gopolicies/word-count-guardrail/go.modpolicies/word-count-guardrail/policy-definition.yamlpolicies/word-count-guardrail/wordcountguardrail.go
| analyticsMetadata := map[string]interface{}{ | ||
| "isGuardrailHit": true, | ||
| "guardrailName": "SemanticPromptGuard", | ||
| } |
There was a problem hiding this comment.
Use kebab-case for guardrailName to maintain consistency.
The guardrailName is set to "SemanticPromptGuard" (PascalCase), but other guardrail policies use kebab-case. This inconsistency could impact analytics aggregation and filtering.
Based on the following examples from other guardrails:
policies/url-guardrail/urlguardrail.go:437uses"url-guardrail"policies/word-count-guardrail/wordcountguardrail.go:413uses"word-count-guardrail"policies/sentence-count-guardrail/sentencecountguardrail.go:415uses"sentence-count-guardrail"
🔧 Proposed fix to use kebab-case naming
analyticsMetadata := map[string]interface{}{
"isGuardrailHit": true,
- "guardrailName": "SemanticPromptGuard",
+ "guardrailName": "semantic-prompt-guard",
}📝 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.
| analyticsMetadata := map[string]interface{}{ | |
| "isGuardrailHit": true, | |
| "guardrailName": "SemanticPromptGuard", | |
| } | |
| analyticsMetadata := map[string]interface{}{ | |
| "isGuardrailHit": true, | |
| "guardrailName": "semantic-prompt-guard", | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@policies/semantic-prompt-guard/semanticpromptguard.go` around lines 619 -
622, Update the analytics metadata to use kebab-case for the guardrail name:
find the analyticsMetadata map where "guardrailName" is set (variable
analyticsMetadata in semanticpromptguard.go) and change the value from
"SemanticPromptGuard" to "semantic-prompt-guard" so it matches other guardrails'
naming convention (e.g., "url-guardrail", "word-count-guardrail"). Ensure no
other occurrences of the PascalCase string remain in that map or nearby
logging/analytics emission code.
| analyticsMetadata := map[string]interface{}{ | ||
| "isGuardrailHit": true, | ||
| "guardrailName": "url-guardrail", | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In github.com/wso2/api-platform/sdk/core v0.1.2, do policy/v1alpha2.DownstreamResponseModifications and policy/v1alpha2.ImmediateResponse include an AnalyticsMetadata field?
💡 Result:
No, policy/v1alpha2.DownstreamResponseModifications and policy/v1alpha2.ImmediateResponse do not include an AnalyticsMetadata field in github.com/wso2/api-platform/sdk/core v0.1.2.
Citations:
- 1: https://github.com/wso2/api-platform
- 2: https://pkg.go.dev/github.com/wso2/api-platform/gateway/gateway-controller/pkg/api/generated
Remove AnalyticsMetadata assignments—these fields do not exist in v0.1.2 SDK structs.
The v0.1.2 release of github.com/wso2/api-platform/sdk/core does not expose AnalyticsMetadata on policy/v1alpha2.DownstreamResponseModifications or policy/v1alpha2.ImmediateResponse. These assignments at lines 809–812, 827–830, and 837–838 will cause a compilation failure.
Either revert these additions or wait for a future SDK release that exposes AnalyticsMetadata on v1alpha2 types.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@policies/url-guardrail/urlguardrail.go` around lines 809 - 812, Remove the
added AnalyticsMetadata assignments: delete the creation/usage of the
analyticsMetadata map and any assignments that set AnalyticsMetadata on
policy/v1alpha2.DownstreamResponseModifications and
policy/v1alpha2.ImmediateResponse (the code that assigns analyticsMetadata to
those structs) because v0.1.2 of github.com/wso2/api-platform/sdk/core does not
expose AnalyticsMetadata; revert those changes so the
DownstreamResponseModifications and ImmediateResponse objects are constructed
without an AnalyticsMetadata field, or guard them behind an SDK-version check
until the SDK adds that field.
Summary by CodeRabbit
New Features
Chores