Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/src/mastra/tools/investigate-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const investigateInputSchema = z.object({
),
primary_keys: z
.record(z.string(), z.string())
.refine((v) => Object.keys(v).length > 0, {
message: "primary_keys must include at least one primary-key value",
})
Comment on lines 14 to +17

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Reject blank PK names/values, not only empty objects.

Line 15 blocks {} but still allows unusable identity input like { "": "" }. Tighten the schema to require non-empty (trimmed) keys and values.

Proposed fix
   primary_keys: z
-    .record(z.string(), z.string())
+    .record(z.string().trim().min(1), z.string().trim().min(1))
     .refine((v) => Object.keys(v).length > 0, {
       message: "primary_keys must include at least one primary-key value",
     })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.record(z.string(), z.string())
.refine((v) => Object.keys(v).length > 0, {
message: "primary_keys must include at least one primary-key value",
})
.record(z.string().trim().min(1), z.string().trim().min(1))
.refine((v) => Object.keys(v).length > 0, {
message: "primary_keys must include at least one primary-key value",
})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/src/mastra/tools/investigate-tool.ts` around lines 14 - 17, The
current Zod schema uses .record(z.string(), z.string()) and only checks for
non-empty object via .refine, which still permits entries like { "": "" };
update the record value/key validators to reject blank or whitespace-only keys
and values by replacing z.string() with a trimmed/non-empty string validator
(e.g., trim then require length>0 or use .transform(s=>s.trim()).min(1) /
.refine(s=>s.trim().length>0, message)) for both key and value, while keeping
the existing .refine that enforces at least one entry and updating its message
to reference primary_keys if desired.

.describe(
"REQUIRED: the primary key column value(s) for this entity. e.g. {\"Company Name\": \"Stripe\"} or {\"First Name\": \"John\", \"Last Name\": \"Doe\"}. You MUST provide at least the primary key values you have found.",
),
Expand Down
4 changes: 3 additions & 1 deletion backend/src/pipeline/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ export const datasetSchemaSchema = z
}

const pkNames = pkCols.map((c) => c.name);
const declaredPk = Array.isArray(data.primary_key)
const declaredPkRaw = Array.isArray(data.primary_key)
? data.primary_key
: [data.primary_key];
const declaredPk = [...new Set(declaredPkRaw)];
if (
declaredPk.length !== declaredPkRaw.length ||
declaredPk.length !== pkNames.length ||
!declaredPk.every((n) => pkNames.includes(n))
) {
Expand Down