Skip to content

fix: validate project chat request bodies before side effects - #283

Merged
willchen96 merged 1 commit into
Open-Legal-Products:mainfrom
snowyukitty:fix/project-chat-request-validation
Aug 4, 2026
Merged

fix: validate project chat request bodies before side effects#283
willchen96 merged 1 commit into
Open-Legal-Products:mainfrom
snowyukitty:fix/project-chat-request-validation

Conversation

@snowyukitty

Copy link
Copy Markdown
Contributor

Summary

Validate project-chat request payloads at runtime before database, document-context, or LLM work. The shared parsers also keep /chat and project chat from drifting apart.

Closes #278. Supersedes the stale implementation in #155.

Why / Motivation

POST /projects/:projectId/chat previously trusted a TypeScript assertion. Malformed values could create a chat and reach downstream document and model work before failing.

Changes

  • Add shared parsers for messages, chat and project IDs, model, displayed and attached documents, and ask_inputs_response.
  • Restrict message roles to user and assistant, normalize accepted strings, and return field-specific 400 details.
  • Validate both chat routes before side effects while preserving canonical filename lookup and spotlighting.
  • Add parser tests and route integration tests that assert malformed project-chat requests do not reach database, document-context, or LLM seams.

Tradeoffs & risks

How verified

  • npm test --prefix backend -- --run src/lib/chat/__tests__/requestValidation.test.ts src/__tests__/integration/chat.routes.test.ts src/__tests__/integration/projectChat.routes.test.ts - 46 passed.
  • npm test --prefix backend - 462 passed, 14 skipped.
  • npm run build --prefix backend
  • A baseline regression test confirmed malformed messages crossed database, document-context, and LLM seams on current main; the candidate route tests verify rejection before those seams.

Checklist

  • Ran the relevant build/test command for the area changed.
  • Reviewed git diff and removed unrelated changes.
  • No documentation or environment example updates are needed for this request-validation fix.
  • No secrets, API keys, real documents, or .env files committed.

@willchen96

Copy link
Copy Markdown
Collaborator

Thanks for the contribution, let me know if you want to join the discord for contributors.

@willchen96
willchen96 merged commit ba979ee into Open-Legal-Products:main Aug 4, 2026
7 checks passed
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.

Validate request bodies for the project chat endpoint

2 participants