custom-builtin-functions
Guidance for creating and registering custom Go functions for Rego policies.
Install
mkdir -p .claude/skills/custom-builtin-functions && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/8538" && unzip -o skill.zip -d .claude/skills/custom-builtin-functions && rm skill.zipInstalls to .claude/skills/custom-builtin-functions
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Create a custom builtin function to be used in the Rego policy engineKey capabilities
- →Define custom Go functions for OPA
- →Register functions with the OPA engine
- →Implement logic using BuiltinContext
- →Use custom functions in Rego policies
How it works
Custom functions are written in Go, registered with the OPA engine, and then invoked within Rego policy files using the chainloop namespace.
Inputs & outputs
When to use custom-builtin-functions
- →Extend OPA policy engine
- →Register custom Go logic for policies
- →Implement complex policy validation
About this skill
Policy Engine Extension
The OPA/Rego policy engine supports custom built-in functions written in Go.
Adding Custom Built-ins:
- Create Built-in Implementation (e.g.,
pkg/policies/engine/rego/builtins/myfeature.go):
package builtins
import (
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/topdown"
"github.com/open-policy-agent/opa/types"
)
const myFuncName = "chainloop.my_function"
func RegisterMyBuiltins() error {
return Register(&ast.Builtin{
Name: myFuncName,
Description: "Description of what this function does",
Decl: types.NewFunction(
types.Args(types.Named("input", types.S).Description("this is the input")),
types.Named("result", types.S).Description("this is the result"),
),
}, myFunctionImpl)
}
func myFunctionImpl(bctx topdown.BuiltinContext, operands []*ast.Term, iter func(*ast.Term) error) error {
// Extract arguments
input, ok := operands[0].Value.(ast.String)
if !ok {
return fmt.Errorf("input must be a string")
}
// Implement logic
result := processInput(string(input))
// Return result
return iter(ast.StringTerm(result))
}
// Autoregisters on package load
func init() {
if err := RegisterMyBuiltins(); err != nil {
panic(fmt.Sprintf("failed to register built-ins: %v", err))
}
}
- Use in Policies (
*.rego):
package example
import rego.v1
result := {
"violations": violations,
"skipped": false
}
violations contains msg if {
output := chainloop.my_function(input.value)
output != "expected"
msg := "Function returned unexpected value"
}
Guidelines:
- Use
chainloop.*namespace for all custom built-ins - Functions that call third party services should be marked as non-restrictive by adding the
NonRestrictiveBuiltincategory to the builtin definition - Always implement proper error handling and return meaningful error messages
- Use context from
BuiltinContextfor timeout/cancellation support - Document function signatures and behavior in the
Descriptionfield and parameter definitions
When not to use it
- →When standard Rego built-ins are sufficient
Prerequisites
Limitations
- →Input must be a string
- →Requires Go implementation for every new function
How it compares
This approach allows extending the OPA engine with custom Go logic rather than relying solely on native Rego expressions.
Compared to similar skills
custom-builtin-functions side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| custom-builtin-functions (this skill) | 0 | 9mo | No flags | Advanced |
| backend-development | 0 | 5mo | No flags | Advanced |
| crypto-firewall-security | 0 | 7mo | No flags | Advanced |
| security-owasp | 0 | 2mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by chainloop-dev
View all by chainloop-dev →You might also like
backend-development
hoadh
Build backends with Node.js, Python, Go (NestJS, FastAPI, Django). Use for REST/GraphQL/gRPC APIs, auth (OAuth, JWT), databases, microservices, security (OWASP), Docker/K8s.
crypto-firewall-security
chartingshow
The agent should prioritize safety, correctness, and explicit validation over convenience or performance shortcuts.
security-owasp
navikt
OWASP Top 10:2025 kodenivå-mønstre for Kotlin, Go, Java og Node.js — tilgangskontroll, forsyningskjede, injeksjon og feilhåndtering
architecture-patterns
wshobson
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use when architecting complex backend systems or refactoring existing applications for better maintainability.
workflow-orchestration-patterns
wshobson
Design durable workflows with Temporal for distributed systems. Covers workflow vs activity separation, saga patterns, state management, and determinism constraints. Use when building long-running processes, distributed transactions, or microservice orchestration.
golang-pro
sickn33
Master Go 1.21+ with modern patterns, advanced concurrency, performance optimization, and production-ready microservices. Expert in the latest Go ecosystem including generics, workspaces, and cutting-edge frameworks. Use PROACTIVELY for Go development, architecture design, or performance optimization.