Skip to content

Commit f558630

Browse files
committed
feat(contact-details): test for hallucinations
1 parent 3849860 commit f558630

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/contact-scraper/test/contacts.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,19 @@ type DetailsSpec = {
5454
[key in keyof typeof JSON_SCHEMA['properties']]?: string[];
5555
}
5656

57-
const testWholeWebsiteDetails = (jsonAnswer: any, expectedWebsiteDetails: DetailsSpec) => {
57+
const testWholeWebsiteDetails = (jsonAnswer: any, expectedWebsiteDetails: DetailsSpec, pageContent: string) => {
5858
for (const [key, urls] of Object.entries(expectedWebsiteDetails)) {
5959
testURLInclusion(key as keyof typeof JSON_SCHEMA['properties'], urls as string[], jsonAnswer);
6060
}
61+
for (const [, items] of Object.entries(jsonAnswer) as [
62+
string,
63+
{ item: string, description: string }[],
64+
][]) {
65+
for (const item of items) {
66+
// avoid hallucinations by ensuring that every returned item is in the page content
67+
expect(pageContent).toContain(item.item);
68+
}
69+
}
6170
};
6271

6372
const testWebsite = async (url: string, spec: DetailsSpec) => {
@@ -75,7 +84,7 @@ const testWebsite = async (url: string, spec: DetailsSpec) => {
7584
});
7685
const { jsonAnswer } = answerResult;
7786
expect(jsonAnswer).not.toBeNull();
78-
testWholeWebsiteDetails(jsonAnswer, spec);
87+
testWholeWebsiteDetails(jsonAnswer, spec, pageContent);
7988
};
8089

8190
test('Scrapes contacts from https://unbounce.com/contact-us/', async () => testWebsite('https://unbounce.com/contact-us/', {

0 commit comments

Comments
 (0)