Skip to content

Chunk Validation#48

Open
exyw wants to merge 2 commits intomasterfrom
refine/chunk-validation
Open

Chunk Validation#48
exyw wants to merge 2 commits intomasterfrom
refine/chunk-validation

Conversation

@exyw
Copy link
Collaborator

@exyw exyw commented Feb 22, 2026

Summary
Adds validation for profile chunks before save: when the user clicks Save (or Save All Changes in the pending-changes modal), all chunks are validated for safety and sensitivity (PII). If any chunk fails, save is blocked and a toast shows the validation error(s).

Changes

  1. Chunk validation scope
    Validate/chunks now checks only safe (no harmful/illegal/NSFW content) and sensitive (no personal PII such as personal phone, email, exact address).
    Removed: name validation (belongsToUser, detectedNames), category validation (categoryValid, categoryMatchesContent), relevance, and the suggestion field.
    Request body no longer requires fullName; only text is used.
  2. Shared validation logic
    lib/resume/validateChunk.ts
    validateChunkText(text, openai) returns { safe, sensitive, reason }.
    Single place for the validation prompt and schema; used by both the API route and the save flow.
  3. Validate/chunks API
    app/api/validate/chunks/route.ts
    Uses validateChunkText from the shared lib (no duplicated prompt/schema).
    Response shape: { safe, sensitive, reason }.
    Keeps existing auth, rate limiting, and body checks.
  4. Validation on save
    app/profile/chunks/actions.ts (Server Action)
    validateChunksAction(chunks: { id, text }[]) validates all non-empty chunks (in parallel).
    Returns { success: true } or { success: false, errors: { chunkId, reason }[] }.
    Requires an authenticated user.
    components/profile/chunks/hooks/useChunkData.ts
    In saveChunks(), after determining there are changes, calls validateChunksAction with current chunks.
    If validation fails: throws an Error with a short message (one chunk: that reason; multiple: e.g. "3 chunks didn't pass validation. <first reason>").
    If validation passes: existing delete/upsert/vector-store logic runs unchanged.
  5. User-facing errors
    components/profile/ActionsButton.tsx
    Save button: catch uses toast.error(err.message) so validation (and other) errors show in a toast.
    Pending-changes modal Save All Changes: same error handling so validation failures from the modal also show a toast.

Behaviour
Save → validate all current chunks → if any fail → one toast with summary (and first reason if multiple) → no DB write.
Save → validate all pass → chunks and categories are saved as before → success toast.

How to test
Edit profile, add or edit a chunk with clearly sensitive content (e.g. personal phone or email) or unsafe content.
Click Save (or Save All Changes in the modal).
Expect a toast with the validation message and no save.
Fix or remove the offending content and save again; expect a successful save and success toast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant