---
name: groq-data-handling
description: |-
  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".
allowed-tools: Read, Write, Edit
version: 1.11.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - groq
  - compliance
compatibility: Designed for Claude Code
title: groq-data-handling
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/groq-data-handling
last_updated: 2026-10-07T06:06:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-data-handling/references/examples.md), [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-data-handling/references/implementation.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/groq-data-handling`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/groq-data-handling`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/groq-data-handling) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/groq-data-handling`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/groq-data-handling --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/groq-data-handling --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# 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](https://groq.com/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](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-data-handling/references/implementation.md).

1. **Sanitize input** — run a PII rule table over every message before it
   leaves your process, flagging which categories were caught:

   ```typescript
   function sanitizeMessages(messages: any[]): { messages: any[]; hadPII: boolean } {
     // apply PII_RULES to each message's content; return redacted copy + flag
   }
   ```

2. **Wrap the completion call** — call `safeCompletion(...)` instead of the raw
   `groq.chat.completions.create`, so input and response both pass the sanitizer.

3. **Track usage** — `trackUsage(model, completion.usage, sessionId)` records
   token counts and estimated cost per call using a per-model price table.

4. **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](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-data-handling/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](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-data-handling/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](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-data-handling/references/implementation.md).
- **Content safety check** with Llama Guard and a **daily cost report** —
  [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-data-handling/references/examples.md).

Minimal end-to-end use once the helpers are in place:

```typescript
const { content, audit } = await auditedCompletion(sessionId, messages);
// content is PII-filtered; audit is a hash-only record safe to persist
```

## Resources

- [Groq Privacy Policy](https://groq.com/privacy-policy/)
- [Groq Pricing](https://groq.com/pricing)
- [Llama Guard (content moderation)](https://console.groq.com/docs/model/meta-llama/llama-guard-4-12b)
- [Full implementation](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-data-handling/references/implementation.md) · [Examples](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/groq-data-handling/references/examples.md)

For enterprise access controls, see the `groq-enterprise-rbac` skill.
