Skip to content

Commit f9b82f0

Browse files
Improve describeSchemaType to show array item type in error messages (#132)
When a required array field is missing, the validation error now reads 'missing required field (expected array of string)' instead of 'missing required field (expected array)'. This makes repair prompts more precise and helps the model produce the correct item type on retry. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5863b97 commit f9b82f0

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

skills/rig/rig.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,15 +2306,16 @@ function describeSchemaType(schema: Schema): string {
23062306
if ("nullable" in schema && schema.nullable === true) {
23072307
return `${describeSchemaType((schema as NullableSchema).inner)} | null`;
23082308
}
2309+
if ("items" in schema) {
2310+
const itemType = describeSchemaType((schema as ArraySchema).items);
2311+
return `array of ${itemType}`;
2312+
}
23092313
if ("type" in schema) {
23102314
return (schema as { type: string }).type;
23112315
}
23122316
if ("enum" in schema) {
23132317
return (schema as EnumSchema).enum.map((v: Json) => JSON.stringify(v)).join(" | ");
23142318
}
2315-
if ("items" in schema) {
2316-
return "array";
2317-
}
23182319
if ("properties" in schema || "additionalProperties" in schema) {
23192320
return "object";
23202321
}

src/rig.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,14 +1684,25 @@ describe("missing required field error message", () => {
16841684
}
16851685
});
16861686

1687-
it("reports a missing required array field with type 'array'", () => {
1687+
it("reports a missing required array field with item type 'array of string'", () => {
16881688
const schema = s.object({ items: s.array(s.string), name: s.string });
16891689
const result = analyzeResponse(JSON.stringify({ name: "x" }), schema, "test", 1);
16901690
expect(result.ok).toBe(false);
16911691
if (!result.ok) {
16921692
expect(result.error.message).toContain("missing required field");
16931693
expect(result.error.message).toContain("$.items");
1694-
expect(result.error.message).toContain("array");
1694+
expect(result.error.message).toContain("array of string");
1695+
}
1696+
});
1697+
1698+
it("reports a missing required array-of-numbers field with item type 'array of number'", () => {
1699+
const schema = s.object({ scores: s.array(s.number), name: s.string });
1700+
const result = analyzeResponse(JSON.stringify({ name: "x" }), schema, "test", 1);
1701+
expect(result.ok).toBe(false);
1702+
if (!result.ok) {
1703+
expect(result.error.message).toContain("missing required field");
1704+
expect(result.error.message).toContain("$.scores");
1705+
expect(result.error.message).toContain("array of number");
16951706
}
16961707
});
16971708

0 commit comments

Comments
 (0)