Skip to content

fix(knowledge): surface KB description validation errors and raise limit to 10k#5347

Merged
waleedlatif1 merged 1 commit into
stagingfrom
debug-kb--description
Jul 2, 2026
Merged

fix(knowledge): surface KB description validation errors and raise limit to 10k#5347
waleedlatif1 merged 1 commit into
stagingfrom
debug-kb--description

Conversation

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator

Summary

  • Raise the knowledge base description limit to 10,000 chars via a shared KNOWLEDGE_BASE_DESCRIPTION_MAX_LENGTH constant, enforced consistently across the create/edit UI, the internal API contract, and the v1 API contract (previously 500 / 1000 / uncapped)
  • Close the internal POST/PUT /api/knowledge gap that had no server-side description cap at all
  • Fix the create-base modal silently blocking submit on validation errors (red field, no message) — now toasts the first error and shows the description error inline
  • Edit modal now toasts on validation failure instead of returning silently

Type of Change

  • Bug fix

Testing

Tested manually. bun run lint, bun run check:api-validation:strict, and tsc --noEmit all pass.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

🤖 Generated with Claude Code

@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 2, 2026 1:21am

Request Review

@cursor

cursor Bot commented Jul 2, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Validation and UX fixes with bounded string length; v1 clients gain a higher description cap (1k → 10k) but no security-sensitive logic changes.

Overview
Introduces KNOWLEDGE_BASE_DESCRIPTION_MAX_LENGTH (10,000) and uses it everywhere knowledge base descriptions are validated, replacing mixed limits (500 in create/edit UI, 1,000 on v1 API, none on internal POST/PUT /api/knowledge).

Create knowledge base modal: react-hook-form invalid submit now toasts the first validation message (via onInvalid) instead of failing silently; description errors show inline on ChipModalField. Primary action uses the same invalid handler.

Edit knowledge base modal: failed client validation toasts the first error instead of returning with no feedback.

API contracts: createKnowledgeBaseBodySchema and v1 create/update bodies enforce the shared max with consistent error text.

Reviewed by Cursor Bugbot for commit 50b1295. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR standardises the knowledge base description length limit to 10,000 characters via a new shared KNOWLEDGE_BASE_DESCRIPTION_MAX_LENGTH constant, and fixes silent UX failures in both the create and edit modals.

  • Constants: Introduces KNOWLEDGE_BASE_DESCRIPTION_MAX_LENGTH = 10_000 in lib/knowledge/constants.ts, replacing ad-hoc 500/1000/uncapped values across UI, internal API, and v1 API contracts.
  • API contracts: Adds a .max(10_000) guard to createKnowledgeBaseBodySchema and updateKnowledgeBaseBodySchema (internal), plus the v1 create/update schemas — closing the previous gap where the internal POST/PUT had no server-side description cap.
  • UX fixes: The create modal now wires onInvalid to react-hook-form's handleSubmit and surfaces the description inline via error={errors.description?.message}; the edit modal's validate() now returns the first error string and toasts it, instead of silently returning.

Confidence Score: 5/5

Safe to merge — all changes are additive validation tightening and UX improvements with no breaking surface.

The constant is introduced cleanly and consumed consistently across UI, internal API, and v1 API. The DB column is PostgreSQL TEXT (unbounded), so no migration is needed for the new 10k limit. The react-hook-form wiring is correct — both the form onSubmit path and the footer button onClick path are updated. The edit modal's validate refactor preserves the original behaviour of setting all inline errors while only toasting the first one. No existing data is at risk of truncation because the new cap (10k) is higher than the previous UI/v1 limits (500/1000).

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/lib/knowledge/constants.ts Adds KNOWLEDGE_BASE_DESCRIPTION_MAX_LENGTH = 10_000 as the single source of truth; DB column is TEXT (unbounded), so no migration is required.
apps/sim/lib/api/contracts/knowledge/base.ts createKnowledgeBaseBodySchema now caps description at 10k chars; updateKnowledgeBaseBodySchema inherits the cap via .pick(), so both POST and PUT are covered.
apps/sim/lib/api/contracts/v1/knowledge/index.ts v1 create and update schemas updated to use shared constant; previously had an independent 1,000-char cap — now aligned.
apps/sim/app/workspace/[workspaceId]/knowledge/components/create-base-modal/create-base-modal.tsx Adds onInvalid callback wired to both form submit paths, passes error prop to description ChipModalField; description validation now surfaces both inline and via toast.
apps/sim/app/workspace/[workspaceId]/knowledge/components/edit-knowledge-base-modal/edit-knowledge-base-modal.tsx validate() refactored to return the first error message string; handleSubmit now toasts the message instead of returning silently.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User types description] --> B{description.length > 10000?}
    B -- No --> C[Validation passes]
    B -- Yes --> D[Inline field error shown]
    D --> E[Toast: first error message]

    subgraph Create Modal
        C --> F[handleSubmit → onSubmit]
        D --> G[handleSubmit → onInvalid callback]
        G --> E
    end

    subgraph Edit Modal
        C --> H[validate returns null → handleSubmit proceeds]
        D --> I[validate returns error string → toast.error]
    end

    subgraph API Contracts
        F --> J[POST /api/knowledge\ncreateKnowledgeBaseBodySchema\nmax 10k]
        F --> K[PUT /api/knowledge/id\nupdateKnowledgeBaseBodySchema\nmax 10k inherited via .pick]
        F --> L[POST /api/v1/knowledge\nv1CreateKnowledgeBaseBodySchema\nmax 10k]
        F --> M[PUT /api/v1/knowledge/id\nv1UpdateKnowledgeBaseBodySchema\nmax 10k]
    end

    J & K & L & M --> N[DB: TEXT column — no length cap]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[User types description] --> B{description.length > 10000?}
    B -- No --> C[Validation passes]
    B -- Yes --> D[Inline field error shown]
    D --> E[Toast: first error message]

    subgraph Create Modal
        C --> F[handleSubmit → onSubmit]
        D --> G[handleSubmit → onInvalid callback]
        G --> E
    end

    subgraph Edit Modal
        C --> H[validate returns null → handleSubmit proceeds]
        D --> I[validate returns error string → toast.error]
    end

    subgraph API Contracts
        F --> J[POST /api/knowledge\ncreateKnowledgeBaseBodySchema\nmax 10k]
        F --> K[PUT /api/knowledge/id\nupdateKnowledgeBaseBodySchema\nmax 10k inherited via .pick]
        F --> L[POST /api/v1/knowledge\nv1CreateKnowledgeBaseBodySchema\nmax 10k]
        F --> M[PUT /api/v1/knowledge/id\nv1UpdateKnowledgeBaseBodySchema\nmax 10k]
    end

    J & K & L & M --> N[DB: TEXT column — no length cap]
Loading

Reviews (1): Last reviewed commit: "fix(knowledge): surface KB description v..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 merged commit 7457184 into staging Jul 2, 2026
17 checks passed
@waleedlatif1 waleedlatif1 deleted the debug-kb--description branch July 2, 2026 01:29
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.

2 participants