Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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.
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.
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.
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.
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.