Skip to content

Commit c3ebfaf

Browse files
authored
fix(llmExtract): remove unsupported JSON schema properties (#1335)
1 parent 387dd3a commit c3ebfaf

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

apps/api/src/__tests__/snips/extract.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ describe("Extract tests", () => {
2929
expect(typeof res.data.is_open_source).toBe("boolean");
3030
expect(res.data.is_open_source).toBe(true);
3131
}, 60000);
32+
33+
it.concurrent("works with unsupported JSON schema parameters", async () => {
34+
const res = await extract({
35+
urls: ["https://firecrawl.dev"],
36+
schema: {
37+
"type": "object",
38+
"properties": {
39+
"company_name": {
40+
"type": "string",
41+
"pattern": "^[a-zA-Z0-9]+$"
42+
},
43+
},
44+
"required": [
45+
"company_name"
46+
]
47+
},
48+
origin: "api-sdk",
49+
});
50+
51+
expect(res.data).toHaveProperty("company_name");
52+
expect(typeof res.data.company_name).toBe("string")
53+
}, 60000);
3254
} else {
3355
it.concurrent("dummy test", () => {
3456
expect(true).toBe(true);

apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,37 @@ export async function performLLMExtract(
365365
export function removeDefaultProperty(schema: any): any {
366366
if (typeof schema !== "object" || schema === null) return schema;
367367

368-
const { default: _, ...rest } = schema;
368+
const rest = { ...schema };
369+
370+
// unsupported global keys
371+
delete rest.default;
372+
373+
// unsupported object keys
374+
delete rest.patternProperties;
375+
delete rest.unevaluatedProperties;
376+
delete rest.propertyNames;
377+
delete rest.minProperties;
378+
delete rest.maxProperties;
379+
380+
// unsupported string keys
381+
delete rest.minLength;
382+
delete rest.maxLength;
383+
delete rest.pattern;
384+
delete rest.format;
385+
386+
// unsupported number keys
387+
delete rest.minimum;
388+
delete rest.maximum;
389+
delete rest.multipleOf;
390+
391+
// unsupported array keys
392+
delete rest.unevaluatedItems;
393+
delete rest.contains;
394+
delete rest.minContains;
395+
delete rest.maxContains;
396+
delete rest.minItems;
397+
delete rest.maxItems;
398+
delete rest.uniqueItems;
369399

370400
for (const key in rest) {
371401
if (Array.isArray(rest[key])) {

0 commit comments

Comments
 (0)