/cohere-pack:cohere-data-handlingfrom cohere-pack
Implements PII redaction and data privacy compliance for Cohere API calls. Detects and redacts emails, phones, SSNs, credit cards, and IPs before sending to Cohere's Chat, Embed, Rerank, or Classify endpoints.
Ships in cohere-pack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Handle sensitive data when calling Cohere APIs. Cohere processes text server-side for Chat, Embed, Rerank, and Classify — any PII in your input reaches their servers. This skill covers pre-call redaction, post-call scrubbing, and compliance patterns.
cohere-ai SDK installedYour App → [PII Redaction] → Cohere API → [Response Scrubbing] → Your App → User
Key point: Everything you send to cohere.chat(), cohere.embed(), etc.
is processed on Cohere's servers. Redact BEFORE the API call.
interface PIIFinding {
type: string;
match: string;
start: number;
end: number;
}
const PII_PATTERNS: Array<{ type: string; regex: RegExp }> = [
{ type: 'email', regex: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g },
{ type: 'phone', regex: /\b(\+\d{1,3}[-.]?)?\d{3}[-.]?\d{3}[-.]?\d{4}\b/g },
{ type: 'ssn', regex: /\b\d{3}-\d{2}-\d{4}\b/g },
{ type: 'credit_card', regex: /\b\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}\b/g },
{ type: 'ip_address', regex: /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g },
];
function detectPII(text: string): PIIFinding[] {
const findings: PIIFinding[] = [];
for (const { type, regex } of PII_PATTERNS) {
for (const match of text.matchAll(new RegExp(regex))) {
findings.push({
type,
match: match[0],
start: match.index!,
end: match.index! + match[0].length,
});
}
}
return findings;
}
function redactPII(text: string): { redacted: string; map: Map<string, string> } {
const map = new Map<string, string>();
let redacted = text;
let counter = 0;
for (const { type, regex } of PII_PATTERNS) {
redacted = redacted.replace(new RegExp(regex), (match) => {
const placeholder = `[${type.toUpperCase()}_${counter++}]`;
map.set(placeholder, match);
return placeholder;
});
}
return { redacted, map };
}
// Usage: redact before sending to Cohere
async function safeCohereChat(userInput: string) {
const { redacted, map } = redactPII(userInput);
const response = await cohere.chat({
model: 'command-a-03-2025',
messages: [{ role: 'user', content: redacted }],
});
// Optionally restore PII in response (for internal use only)
let answer = response.message?.content?.[0]?.text ?? '';
for (const [placeholder, original] of map) {
answer = answer.replace(placeholder, original);
}
return answer;
}
// Embeddings are stored long-term in vector DBs — ensure no PII
async function safeEmbed(texts: string[]): Promise<number[][]> {
// Check for PII before embedding
for (const text of texts) {
const pii = detectPII(text);
if (pii.length > 0) {
console.warn(`PII detected in embed input: ${pii.map(p => p.type).join(', ')}`);
// Option 1: Redact and embed
// Option 2: Reject and throw
throw new Error(`PII found in embedding input: ${pii.map(p => p.type).join(', ')}`);
}
}
return cohere.embed({
model: 'embed-v4.0',
texts,
inputType: 'search_document',
embeddingTypes: ['float'],
}).then(r => r.embeddings.float);
}
// Classify endpoint receives text + examples — minimize both
async function safeClassify(inputs: string[]) {
// Redact PII from classification inputs
const safeInputs = inputs.map(text => redactPII(text).redacted);
return cohere.classify({
model: 'embed-english-v3.0',
inputs: safeInputs,
examples: [
// Examples should never contain real PII
{ text: 'This product is great', label: 'positive' },
{ text: 'Amazing experience', label: 'positive' },
{ text: 'Terrible service', label: 'negative' },
{ text: 'Very disappointed', label: 'negative' },
],
});
}
interface CohereAuditEntry {
timestamp: Date;
endpoint: string;
model: string;
piiDetected: string[];
redacted: boolean;
tokensUsed: { input: number; output: number };
userId?: string;
}
async function auditCohereCall(entry: CohereAuditEntry): Promise<void> {
// Log to database (not console — structured storage)
await db.cohereAudit.insert({
...entry,
// Never log the actual API input/output — only metadata
});
}
// Usage
async function auditedChat(userId: string, message: string) {
const pii = detectPII(message);
const { redacted } = redactPII(message);
const response = await cohere.chat({
model: 'command-a-03-2025',
messages: [{ role: 'user', content: redacted }],
});
await auditCohereCall({
timestamp: new Date(),
endpoint: 'chat',
model: 'command-a-03-2025',
piiDetected: pii.map(p => p.type),
redacted: pii.length > 0,
tokensUsed: {
input: response.usage?.billedUnits?.inputTokens ?? 0,
output: response.usage?.billedUnits?.outputTokens ?? 0,
},
userId,
});
return response;
}
// Cohere's built-in safety modes (separate from PII — these handle harmful content)
await cohere.chat({
model: 'command-a-03-2025',
messages: [{ role: 'user', content: userInput }],
safetyMode: 'STRICT', // Maximum content filtering
// Options: 'CONTEXTUAL' (default), 'STRICT', 'OFF'
// Note: Not configurable when using tools or documents
});
| Data | Retention | Action |
|---|---|---|
| API request logs (redacted) | 30 days | Auto-delete |
| Audit entries | 7 years | Archive to cold storage |
| Cached embeddings | Until source changes | Invalidate on update |
| Cohere API responses | Do not persist | Process in memory only |
| PII mappings | Per-request only | Never persist |
| Issue | Cause | Solution |
|---|---|---|
| PII in embeddings | Missing pre-check | Add detectPII before embed |
| Redaction breaks context | Over-aggressive regex | Use domain-specific patterns |
| Audit gap | Async logging failed | Use sync fallback |
| Safety mode ignored | Used with tools/docs | Separate safety from RAG calls |
For enterprise access control, see cohere-enterprise-rbac.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
24 skills in this plugin
/cohere-ci-integrationConfigure CI/CD for Cohere integrations with GitHub Actions and automated testing.
Use when setting up automated testing for Chat/Embed/Rerank,
configuring CI pipelines, or testing Cohere-powered applications.
Trigger with phrases like "cohere CI", "cohere GitHub Actions",
"cohere automated tests", "CI cohere", "cohere pipeline".
/cohere-common-errorsDiagnose and fix Cohere API v2 errors and exceptions.
Use when encountering Cohere errors, debugging failed requests,
or troubleshooting CohereError, CohereTimeoutError, rate limits.
Trigger with phrases like "cohere error", "fix cohere",
"cohere not working", "debug cohere", "cohere 429", "cohere 400".
/cohere-core-workflow-aBuild a complete RAG pipeline with Cohere Chat, Embed, and Rerank.
Use when implementing retrieval-augmented generation, building
grounded Q&A systems, or combining search with LLM generation.
Trigger with phrases like "cohere RAG", "cohere retrieval",
"cohere grounded generation", "cohere search and answer".
/cohere-core-workflow-bBuild tool-use agents and function calling with Cohere API v2.
Use when implementing multi-step agents, function calling,
or building autonomous tool-using workflows with Cohere.
Trigger with phrases like "cohere tool use", "cohere agents",
"cohere function calling", "cohere multi-step".
/cohere-cost-tuningOptimize Cohere costs through model selection, token budgets, and usage monitoring.
Use when analyzing Cohere billing, reducing API costs,
or implementing usage monitoring and budget alerts.
Trigger with phrases like "cohere cost", "cohere billing",
"reduce cohere costs", "cohere pricing", "cohere expensive", "cohere budget".
/cohere-debug-bundleCollect Cohere debug evidence for support tickets and troubleshooting.
Use when encountering persistent issues, preparing support tickets,
or collecting diagnostic information for Cohere API problems.
Trigger with phrases like "cohere debug", "cohere support bundle",
"collect cohere logs", "cohere diagnostic".
npx claudepluginhub flight505/skill-forge --plugin cohere-packOther plugins' skills for the same job