Skip to content

Commit 8f5bd2b

Browse files
committed
fix: prevent member organization title overflow during enrichment
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
1 parent 77c91ef commit 8f5bd2b

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

  • services
    • apps/members_enrichment_worker/src/activities
    • libs/data-access-layer/src/old/apps/members_enrichment_worker

services/apps/members_enrichment_worker/src/activities/llm.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ export async function squashWorkExperiencesWithLLM(
272272
If multiple roles from the same organization overlap in time IN DIFFERENT SOURCES, squash them into one entry with a unified startDate, endDate, and picked information (e.g., job titles, descriptions).
273273
Preserve all unique identities and consolidate other fields appropriately.
274274
If necessary, ONLY merge dateRanges and NEVER merge titles together, but pick the one that best represents the role.
275+
Job Titles:
276+
Return only a concise professional job title (e.g. "Software Engineer", "Engineering Manager"). Do not return job descriptions, responsibilities, or full sentences. If the input is a description, infer the most appropriate professional job title.
277+
Never return job descriptions, responsibilities, or full sentences.
278+
If the input is a description, infer the most appropriate professional job title.
275279
Handle Missing Dates:
276280
Use logical assumptions to fill gaps where possible, always using existing date information but nothing else.
277281
If there is a role with a missing startDate and a missing endDate, and there's also another role from same or similar organization with dates, you can remove the role with missing dates.

services/libs/data-access-layer/src/old/apps/members_enrichment_worker/index.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ import {
1414
OrganizationSource,
1515
} from '@crowd/types'
1616

17+
function truncateTitle(title: string | null | undefined) {
18+
const maxLength = 255
19+
20+
if (title == null || title.length <= maxLength) {
21+
return title
22+
}
23+
24+
return title.slice(0, maxLength)
25+
}
26+
1727
export async function fetchMemberDataForLLMSquashing(
1828
db: DbConnOrTx,
1929
memberId: string,
@@ -483,15 +493,24 @@ export async function updateMemberOrg(
483493
return null
484494
}
485495

496+
const normalizedToUpdate = { ...toUpdate }
497+
if (typeof normalizedToUpdate.title === 'string') {
498+
normalizedToUpdate.title = truncateTitle(normalizedToUpdate.title)
499+
}
500+
486501
// First check if another row like this exists so that we don't get unique index violations.
487502
// We compute the "target" state after applying toUpdate to decide what to look for.
488503
const params = {
489504
memberId,
490505
id: original.id,
491506
organizationId: original.orgId,
492507
// Use updated value if provided, otherwise keep original
493-
dateStart: toUpdate.dateStart !== undefined ? toUpdate.dateStart : original.dateStart,
494-
dateEnd: toUpdate.dateEnd !== undefined ? toUpdate.dateEnd : original.dateEnd,
508+
dateStart:
509+
normalizedToUpdate.dateStart !== undefined
510+
? normalizedToUpdate.dateStart
511+
: original.dateStart,
512+
dateEnd:
513+
normalizedToUpdate.dateEnd !== undefined ? normalizedToUpdate.dateEnd : original.dateEnd,
495514
}
496515

497516
let dateEndFilter = `and "dateEnd" = $(dateEnd)`
@@ -538,7 +557,7 @@ export async function updateMemberOrg(
538557
{
539558
memberId,
540559
id: original.id,
541-
...toUpdate,
560+
...normalizedToUpdate,
542561
},
543562
)
544563

@@ -554,6 +573,8 @@ export async function insertWorkExperience(
554573
dateEnd: string | null,
555574
source: OrganizationSource,
556575
): Promise<string | null> {
576+
const truncatedTitle = truncateTitle(title)
577+
557578
let conflictCondition = `("memberId", "organizationId", "dateStart", "dateEnd")`
558579
if (!dateEnd) {
559580
conflictCondition = `("memberId", "organizationId", "dateStart") WHERE "dateEnd" IS NULL`
@@ -574,7 +595,7 @@ export async function insertWorkExperience(
574595
${onConflict}
575596
RETURNING id;
576597
`,
577-
[memberId, orgId, title, dateStart, dateEnd, source],
598+
[memberId, orgId, truncatedTitle, dateStart, dateEnd, source],
578599
)
579600

580601
return result?.id ?? null

0 commit comments

Comments
 (0)