Groq Data Handling
Overview
Manage data flowing through Groq's inference API. This skill wires a privacy
pipeline around the Groq SDK: sanitize prompts before they are sent, filter
responses after they return, redact PII, hash-log an audit trail, and track
token usage and cost. Key fact: Groq does not use API data for model training
(Groq Privacy Policy).
Prerequisites
- Node.js project with the
groq-sdk package installed (npm i groq-sdk).
- A Groq API key exported as
GROQ_API_KEY. The SDK reads it automatically
from the environment — new Groq() needs no explicit argument. Never hardcode
the key; keep it in an untracked .env or your secret manager.
- Node's built-in
crypto module (for the audit hash) — no install needed.
Instructions
The pipeline layers in four stages; drop simple add-ons (moderation, cost
reporting) on top. Each snippet below is the skeleton — the full, copy-ready
code for every stage is in references/implementation.md.
Sanitize input — run a PII rule table over every message before it
leaves your process, flagging which categories were caught:
function sanitizeMessages(messages: any[]): { messages: any[]; hadPII: boolean } {
// apply PII_RULES to each message's content; return redacted copy + flag
}
Wrap the completion call — call safeCompletion(...) instead of the raw
groq.chat.completions.create, so input and response both pass the sanitizer.
Track usage — trackUsage(model, completion.usage, sessionId) records
token counts and estimated cost per call using a per-model price table.
Audit — auditedCompletion(...) ties it together and logs a SHA-256
hash of the prompt (never the prompt text) so the audit trail carries no
sensitive content.
For content moderation via Llama Guard and a daily cost report, see
references/examples.md.
Groq data policy
- Groq does not train on API request/response data.
- Prompts and completions are processed and discarded.
- Groq may temporarily log requests for abuse prevention.
- For enterprise: contact Groq for DPA and SOC 2 compliance details.
Output
- Sanitized messages/responses — text with
[EMAIL], [PHONE], [SSN],
[CARD], [IP] placeholders swapped in for detected PII, plus a hadPII
boolean and a list of redacted categories.
- Usage records — one JSON line per call (
type: "groq_usage") with model,
token counts, and estimatedCostUsd.
- Audit entries — one JSON line per call (
type: "groq_audit") carrying a
prompt hash, piiDetected, responseFiltered, and the usage record.
- Cost report — an aggregated object with
totalCost, totalTokens,
totalCalls, and a per-model breakdown (see the sample in
references/examples.md).
Error Handling
| Issue |
Cause |
Solution |
| PII leaks in response |
Model echoes sensitive input |
Apply response filtering on all completions |
| Cost spike |
70B model for all requests |
Route simple tasks to 8B |
| Missing usage data |
Streaming mode |
Use non-streaming for tracked requests, or estimate |
| Audit gaps |
Not all code paths use wrapper |
Lint rule: ban direct groq.chat.completions.create |
GROQ_API_KEY not set |
Key missing from environment |
Export the key before running; the SDK throws on an unauthenticated call |
Examples
- Full four-stage pipeline (sanitizer, safe wrapper, usage tracker,
audited completion) — references/implementation.md.
- Content safety check with Llama Guard and a daily cost report —
references/examples.md.
Minimal end-to-end use once the helpers are in place:
const { content, audit } = await auditedCompletion(sessionId, messages);
// content is PII-filtered; audit is a hash-only record safe to persist
Resources
For enterprise access controls, see the groq-enterprise-rbac skill.
Source: jeremylongshore/claude-code-plugins-plus-skills → plugins/saas-packs/groq-pack/skills/groq-data-handling/SKILL.md
1---2name: groq-data-handling3description: "| Use when you need to keep PII out of Groq API calls, filter model responses, audit-log conversations, or track token cost and usage for a Groq integration. Implements prompt sanitization, PII redaction, response filtering, and usage tracking. Trigger with phrases like \"groq data\", \"groq PII\", \"groq GDPR\", \"groq data retention\", \"groq privacy\", \"groq compliance\"."4allowed-tools: "Read, Write, Edit"5category: security-and-compliance6source_repo: jeremylongshore/claude-code-plugins-plus-skills7source_path: "plugins/saas-packs/groq-pack/skills/groq-data-handling/SKILL.md"8source_url: https://github.com/jeremylongshore/claude-code-plugins-plus-skills/blob/HEAD/plugins/saas-packs/groq-pack/skills/groq-data-handling/SKILL.md9---1011# Groq Data Handling1213## Overview1415Manage data flowing through Groq's inference API. This skill wires a privacy16pipeline around the Groq SDK: sanitize prompts before they are sent, filter17responses after they return, redact PII, hash-log an audit trail, and track18token usage and cost. Key fact: Groq does not use API data for model training19([Groq Privacy Policy](https://groq.com/privacy-policy/)).2021## Prerequisites2223- Node.js project with the `groq-sdk` package installed (`npm i groq-sdk`).24- A Groq API key exported as `GROQ_API_KEY`. The SDK reads it automatically25 from the environment — `new Groq()` needs no explicit argument. Never hardcode26 the key; keep it in an untracked `.env` or your secret manager.27- Node's built-in `crypto` module (for the audit hash) — no install needed.2829## Instructions3031The pipeline layers in four stages; drop simple add-ons (moderation, cost32reporting) on top. Each snippet below is the skeleton — the full, copy-ready33code for every stage is in [references/implementation.md](references/implementation.md).34351. **Sanitize input** — run a PII rule table over every message before it36 leaves your process, flagging which categories were caught:3738 ```typescript39 function sanitizeMessages(messages: any[]): { messages: any[]; hadPII: boolean } {40 // apply PII_RULES to each message's content; return redacted copy + flag41 }42 ```43442. **Wrap the completion call** — call `safeCompletion(...)` instead of the raw45 `groq.chat.completions.create`, so input and response both pass the sanitizer.46473. **Track usage** — `trackUsage(model, completion.usage, sessionId)` records48 token counts and estimated cost per call using a per-model price table.49504. **Audit** — `auditedCompletion(...)` ties it together and logs a SHA-25651 hash of the prompt (never the prompt text) so the audit trail carries no52 sensitive content.5354For content moderation via Llama Guard and a daily cost report, see55[references/examples.md](references/examples.md).5657### Groq data policy5859- Groq does **not** train on API request/response data.60- Prompts and completions are processed and discarded.61- Groq may temporarily log requests for abuse prevention.62- For enterprise: contact Groq for DPA and SOC 2 compliance details.6364## Output6566- **Sanitized messages/responses** — text with `[EMAIL]`, `[PHONE]`, `[SSN]`,67 `[CARD]`, `[IP]` placeholders swapped in for detected PII, plus a `hadPII`68 boolean and a list of redacted categories.69- **Usage records** — one JSON line per call (`type: "groq_usage"`) with model,70 token counts, and `estimatedCostUsd`.71- **Audit entries** — one JSON line per call (`type: "groq_audit"`) carrying a72 prompt hash, `piiDetected`, `responseFiltered`, and the usage record.73- **Cost report** — an aggregated object with `totalCost`, `totalTokens`,74 `totalCalls`, and a per-model breakdown (see the sample in75 [references/examples.md](references/examples.md)).7677## Error Handling7879| Issue | Cause | Solution |80|-------|-------|----------|81| PII leaks in response | Model echoes sensitive input | Apply response filtering on all completions |82| Cost spike | 70B model for all requests | Route simple tasks to 8B |83| Missing usage data | Streaming mode | Use non-streaming for tracked requests, or estimate |84| Audit gaps | Not all code paths use wrapper | Lint rule: ban direct `groq.chat.completions.create` |85| `GROQ_API_KEY` not set | Key missing from environment | Export the key before running; the SDK throws on an unauthenticated call |8687## Examples8889- **Full four-stage pipeline** (sanitizer, safe wrapper, usage tracker,90 audited completion) — [references/implementation.md](references/implementation.md).91- **Content safety check** with Llama Guard and a **daily cost report** —92 [references/examples.md](references/examples.md).9394Minimal end-to-end use once the helpers are in place:9596```typescript97const { content, audit } = await auditedCompletion(sessionId, messages);98// content is PII-filtered; audit is a hash-only record safe to persist99```100101## Resources102103- [Groq Privacy Policy](https://groq.com/privacy-policy/)104- [Groq Pricing](https://groq.com/pricing)105- [Llama Guard (content moderation)](https://console.groq.com/docs/model/meta-llama/llama-guard-4-12b)106- [Full implementation](references/implementation.md) · [Examples](references/examples.md)107108For enterprise access controls, see the `groq-enterprise-rbac` skill.109110---111112**Source:** [`jeremylongshore/claude-code-plugins-plus-skills`](https://github.com/jeremylongshore/claude-code-plugins-plus-skills) → `plugins/saas-packs/groq-pack/skills/groq-data-handling/SKILL.md`