SDK — Policies

The rivano.policies resource lets you manage declarative governance rules programmatically. Policies fire on every proxied request or response and take one of three actions: block, redact, or warn.

List policies

import Rivano from '@rivano/sdk';

const rivano = new Rivano({ apiKey: 'rv_...' });

const { data, total } = await rivano.policies.list();
for (const policy of data) {
  console.log(`${policy.name} [${policy.onPhase}] → ${policy.action} (${policy.enabled ? 'on' : 'off'})`);
}

Create a policy

import Rivano from '@rivano/sdk';

const rivano = new Rivano({ apiKey: 'rv_...' });

const policy = await rivano.policies.create({
  name: 'block-prompt-injection',
  description: 'Block requests with injection score >= 0.7',
  onPhase: 'request',
  conditionType: 'injection_score',
  conditionConfig: { threshold: 0.7 },
  action: 'block',
  enabled: true,
});

console.log('Policy created:', policy.id);

Create parameters

ParameterTypeRequiredDescription
namestringYesUnique policy name
descriptionstringNoHuman-readable description
onPhase'request' | 'response'YesWhen to evaluate: before or after the LLM call
conditionTypestringYesSee condition types below
conditionConfigobjectYesConfiguration for the condition
action'block' | 'redact' | 'warn'YesWhat to do when the condition is met
enabledbooleanNoWhether the policy is active (default: true)
teamIdstringNoScope policy to a specific team

Condition types

conditionTypePhaseconditionConfig fieldsDescription
injection_scorerequestthreshold: number (0–1)Block/warn if injection risk score ≥ threshold
pii_detectedrequest or responsetypes?: string[]Fire if PII is detected (email, phone, SSN, etc.)
token_countrequestmaxTokens: numberFire if estimated token count exceeds limit
model_namerequestallowlist?: string[], denylist?: string[]Fire if model is not in allowlist or is in denylist

Update a policy

import Rivano from '@rivano/sdk';

const rivano = new Rivano({ apiKey: 'rv_...' });

const updated = await rivano.policies.update('policy_abc123', {
  enabled: false,
  conditionConfig: { threshold: 0.6 },
});

Delete a policy

await rivano.policies.delete('policy_abc123');

Policy templates

Rivano ships a set of curated policy templates. List them or apply a full template pack:

List available templates

import Rivano from '@rivano/sdk';

const rivano = new Rivano({ apiKey: 'rv_...' });

const templates = await rivano.policies.templates();
for (const t of templates) {
  console.log(t.pack, t.name, t.action);
}

Apply the foundational pack

import Rivano from '@rivano/sdk';

const rivano = new Rivano({ apiKey: 'rv_...' });

// Applies 4 policies at once:
// - block-injection (request, block)
// - redact-pii-response (response, redact)
// - warn-large-prompt (request, warn, >4000 tokens)
// - block-ssn (request, block)
const policies = await rivano.policies.applyTemplate('foundational');
console.log(`Applied ${policies.length} policies`);
💡

The foundational pack is the fastest way to get meaningful governance in place. You can customize any of the applied policies afterward via policies.update().

Error handling

ErrorWhen it occurs
SdkAuthErrorInvalid API key
SdkNotFoundErrorPolicy ID does not exist
SdkErrorInvalid condition type or action combination