Blog

Detecting a job change from code means diffing the first experience group, not the headline

A headline edit is not a job change. Store the last record, re-read it, and compare the current employer and role. Here is the diff, and the cases that fool it.

The Triguna team 26 October 2026

A code diff panel showing the first experience entry company and title removed and added while the headline is ignored, beside the headline "Diff the experience, not the headline."

A job change is the most useful signal in a person record and the easiest one to detect wrongly. The obvious approach, compare the headline you stored with the headline you just fetched, fires on every rewritten tagline and misses the person who moved company and kept the same headline for three months.

The reliable signal is structural. A person record groups employment by employer in experience[], most recent first, and each group holds positions[] with a date_range. A job change shows up there as a new first group, or as the old first position gaining an end date. Detect that and you have a change. Detect a different headline and you have a different headline.

What actually changes when someone moves

There are three shapes worth telling apart, because they mean different things to the system reading them.

What happenedWhat the record showsWhat to do
Moved to a new companya new experience[0] with a different company_idtreat as a job change
Promoted, same companysame experience[0], a new positions[0] with a new titletreat as a role change
Left, nothing new yetpositions[0].date_range.end is now settreat as departed
Edited their headlineheadline differs, experience[0] unchangedignore for routing

The promotion row is the one that catches people out. experience[] groups by employer, so a promotion does not add a group. It adds a position inside the existing one. The person records guide covers why the title lives on the position and not on the group, and the same rule decides how you diff.

The diff

Keep the last payload you fetched, which is the premise of storing the raw payload, and compare the parts that matter.

type DateRange = { start?: { year?: number; month?: number | null } | null; end?: unknown | null };
type Position = { title?: string | null; date_range?: DateRange | null };
type Group = { company_id?: string | null; company_name?: string | null; positions?: Position[] | null };
type Person = { entity_urn: string; experience?: Group[] | null };

type Change =
  | { kind: 'none' }
  | { kind: 'company'; from: string | null; to: string | null }
  | { kind: 'role'; from: string | null; to: string | null }
  | { kind: 'departed'; company: string | null }
  | { kind: 'unknown' };

const current = (p: Person) => {
  const group = p.experience?.[0];
  const position = group?.positions?.[0];
  return {
    companyId: group?.company_id ?? null,
    company: group?.company_name ?? null,
    title: position?.title ?? null,
    ended: position?.date_range?.end != null,
  };
};

export function diffJob(before: Person, after: Person): Change {
  const a = current(before);
  const b = current(after);

  // No experience on either side is not evidence of anything.
  if (!a.companyId && !b.companyId) return { kind: 'unknown' };

  if (a.companyId !== b.companyId) return { kind: 'company', from: a.company, to: b.company };
  if (!a.ended && b.ended) return { kind: 'departed', company: b.company };
  if (a.title !== b.title) return { kind: 'role', from: a.title, to: b.title };
  return { kind: 'none' };
}

Compare company_id, not company_name. Names get reformatted (“Acme” becomes “Acme, Inc.”), while the id is what you join to a company record anyway.

The cases that fool a naive diff

More than one current role. Someone with a full time job and an advisory seat can have two groups with no end date, and which one sits first is not a statement about which is their main job. If your routing depends on the primary employer, compare the set of company_id values with no end date rather than only the first group, and only fire when a company enters or leaves that set.

An empty or thin record. A 200 with no experience is a resolved profile that holds little, not a person who left their job. The unknown branch above exists so that a thin record never reads as a departure. Handling partial records covers the general rule: absence of a field is not a value.

A 404 on a profile you used to resolve. A slug that stopped resolving usually means the public identifier changed, because public_identifier is user editable. It does not mean the person left. Look them up again by the entity_urn you stored, which profile_id accepts as input, and why a lookup returns 404 has the rest of that class. Do not retry the old slug: a 404 costs a credit every time.

Backdated changes. People often update their profile weeks after they start a new job, and the start date they enter is the real one. If you report “changed jobs this week” off the date you noticed, say so in the field name. detected_at and started_at are different facts.

Fetching the second read

The diff needs a fresh record, and a fresh record is a billed lookup. One credit per answered profile at $0.005, listed on pricing, so watching 10,000 people once a month is 10,000 credits, and the cost is set entirely by how often you re-read.

curl -sS "https://api.triguna.ai/v1/people/profile?profile_id=$ENTITY_URN" \
  -H "ApiKey: $TRIGUNA_KEY" -D -

Read X-Credits-Charged as a number, not an int, because credits are decimal. use_cache defaults to true, and a stored copy under 24 hours old is served instantly. For a monthly job change sweep that is what you want, so leave it on.

If you already hold the entity_urn values, and for a watch list you should, POST /v1/people/bulk takes 1 to 50 bare urns a call. It bills exactly what single lookups would, 1 credit per profile returned, so it saves round trips and rate limit headroom, not money. One stale urn turns the whole batch into a 502 charged 1 credit, and you retry in smaller batches to find it. Enriching a list covers the pacing at the published 10 requests per second.

What to do with the signal

Write the change, not just the new state. A row in a job_changes table with the person, the kind of change, the before and after values, and detected_at is what downstream systems actually want: the CRM to update the contact, the sales team to follow the person to their new company, and the account owner at the old company to know their champion has gone.

create table job_changes (
  entity_urn   text not null,
  kind         text not null,          -- company | role | departed
  from_value   text,
  to_value     text,
  detected_at  timestamptz not null default now()
);

Keep the old payload when you store the new one. A diff you cannot reproduce later is a signal nobody will trust the second time it fires.

Next

job-changesdata-qualityrefreshsignals

Start with one request

Free credits on signup, no card required. Usage-based pricing after that.