Skip to content
Judd Gurtman

← All work

Lead router on Palantir Foundry

A small plumbing and heating shop gets leads at all hours, and some of them are emergencies. I built a lead router for a made-up shop: it labels each lead, drafts a reply from the shop's own records, and holds every draft in a queue for a person. The data is fictional, and nothing is sent.

Built
October 2026
Stack
Ontology, AIP Logic, AIP Evals, Workshop, TypeScript, Claude
Tested by
56 test leads, drafted 3 times each (168 calls a run), 6 scored runs
Data
Fictional. Nothing is sent.
Built with
Claude Code as my pair programmer
The review queue in Workshop: leads sorted with safety leads first, a no-heat message from a customer with a 6-month-old, and a draft reply that opens with safety steps above Approve, Edit and Reject buttons
The review queue. Safety leads sort to the top. This one is a no-heat call with a 6-month-old in the house. Code puts the safety steps at the top of the reply, and a person approves, edits or rejects it.
A spam lead offering search rankings, with a draft whose reply is NO_REPLY and whose status is pending
Spam. The draft is NO_REPLY. Approve and Edit are blocked for it, so it can only be rejected.
The Ontology's seven object types with their counts: Opening 38, Customer 30, Decision 1, Draft 4, Job 95, Service 27 and Lead 56
The Ontology. Seven object types: Lead, Customer, Job, Service, Opening, Draft and Decision. 56 leads, 30 customers and 95 past jobs.
The evaluation suite's list of runs from October 11 to October 26, each with 168 test cases and an average duration of 8 to 10 seconds
Scored runs. Each run drafts every lead three times, 168 calls, so I can see what a prompt change did.

What it is

A slow reply loses the job, because people call the next company on the list. So I built a lead router for a made-up shop on Palantir's AIP Developer Tier. A classifier in AIP Logic labels each lead by category, urgency and safety hazard. Then a drafting step writes a reply from the shop's own records: customers, past jobs, prices and open appointment windows. Every draft lands in a Workshop queue, where a person approves, edits or rejects it.

Code decides which leads are red, puts the safety instructions at the top of a reply, and checks every fact in a draft before a person sees it.

  1. 01
    A lead arrives Fictional data

    A message to the shop, at any hour. Some are emergencies and some are spam.

  2. 02
    Safety floor A SQL rule, no model

    Reads the subject, the message and the outdoor temperature and flags gas, carbon monoxide, flooding or no heat. A hit makes the lead red and sends it to a person.

  3. 03
    Classify Claude Sonnet 5.5, in AIP Logic

    Labels the lead by category, urgency and safety hazard.

  4. 04
    Draft TypeScript functions and one model call

    Code gathers the shop's records for this customer (past jobs, prices, open appointment windows) and builds the prompt. The model writes the reply.

  5. 05
    Check Code

    Puts the safety instructions at the top of a safety reply and checks every fact in the draft before a person sees it.

  6. 06
    Review A person, in a Workshop queue

    Approves, edits or rejects. A spam draft can only be rejected, and an edit to a safety reply has to keep the full safety opening.

The results

Every run drafts the 56 test leads 3 times, 168 calls. The runs are numbered 1 to 6, from October 9 to October 26, 2026.

WhatBeforeAfterMeasured on
Calls with every field right79 of 16899 of 168Run 3 (Oct 12, prompt v2) vs. run 5 (Oct 26, prompt v4), on the final key and one judge wording
Calls with a false safety opening150Every run from 1 to 5 vs. run 6 (Oct 26), the first after the safety rule became flag-only
Safety-lead calls that got their opening48 of 48Run 6
Blind safety leads: the classifier72 of 7224 leads written by a separate session, 3 calls each (Oct 26)
Blind safety leads: my SQL rule6 of 12The real hazards among those 24 leads. It also left 7 of the 12 lookalikes alone
Time to draftabout 9 sThe median per eval call in run 6. The 90th percentile was 13 seconds

How it's tested

Scoring runs in AIP Evals. Code grades two things: whether the draft matched the right customer, and whether it cited exactly the records it should. An LLM judge from a different model family grades what the reply says and what it avoids. My own script re-scores every exported run, and it has never disagreed with the platform on the code-graded fields.

The judge is noisier. In run 6 it failed one lead (L025) on all 3 calls for not saying the price covered sink drains, though the reply quoted the listed price.

The drafting rules started as Python on my laptop and became TypeScript functions on Foundry, with the prompt inside that code. A parity test checks that the TypeScript builds the exact same prompt as the Python, byte for byte. It matches on 144 of 144 prompts.

The classifier, v1 to v2

I froze v1's prompt before it saw a lead. On the first 40 leads, it got all three labels right on every run for 32 of them. Safety was 120 of 120 calls, and urgency was the weakest at 107 of 120. I wrote v2 after seeing v1's misses, so its perfect score on those 40 is a training score and I don't count it.

On 8 held-out leads, v1 got 3 right on every run and v2 got all 8. The catch is that those 8 were written from the rules v2 encodes. The miss I remember is a chirping carbon monoxide detector that v1 called a question with no urgency, on all 3 runs. On 8 later safety leads, written by a fresh Claude session that hadn't seen any prompt or result, v2 got all 24 calls right.

Keeping the test honest

From the second draft prompt on, a fresh Claude session wrote each prompt from a short brief, without seeing the results or the answer key. The held-out leads came from sessions like that too, and so did anything else that could be tuned to the test.

The answer key changed four times. Every old key stays byte for byte as it was, so I can re-score any old run exactly, and the answers live only in the keys and the eval suites, never anywhere a function can read.

Four draft prompts

Facts are the cleanest trend, because code grades them. Calls that cited exactly the records in the key went from 41 of 144 on v1 (run 1) to 102, 102, 123, 122 and 115 of 168 in runs 2 to 6. I reworded the judge's rubric at run 3, so its scores only compare within runs 1 and 2 and within runs 3 to 6. From run 3 on, calls with every field right went 79, 99, 99 and 98 of 168.

Each prompt answered the run before it.

  • v1 was the baseline for run 1.
  • v2 moved the "marked urgent" line into code. Replies cite the customer's own record, give price ranges and past jobs, offer windows only for a visit, and ask new senders for a phone number.
  • v3 tells a safety customer with a booked job not to wait for it, and a quote offers the free estimate, with no appointment windows unless the customer asks for them.
  • v4 treats a customer asking "when" as wanting a visit, names the booked job, and gives a past job its date.

I stopped after run 5, when v4 matched v3 at 99 of 168 calls with every field right, and wrote the leftover misses down as known limits instead of writing a fifth prompt.

The safety floor

The safety floor is a SQL rule with no model in it. It reads a lead's subject, message and the outdoor temperature and flags gas, carbon monoxide, flooding or no heat. At first a floor hit also chose the safety opening a draft starts with. On the 56 leads it was right on 50, with 5 false flags and 1 miss.

Those 5 false flags put a safety opening on 15 calls in every run from 1 to 5. For most of the project my notes blamed the classifier for them. They were the floor's.

Then I had a separate Claude session write 24 test leads for the floor, 12 real hazards and 12 lookalikes. Nobody has read their messages. The floor caught 6 of the 12 hazards and left 7 of the 12 lookalikes alone. The classifier got all 72 calls right.

So the floor only raises a flag now. A hit still makes the lead red and sends it to a person, but the opening comes from the classifier. Run 6 was the first with that change. It had no false openings, all 48 calls on safety leads got their opening, and the judge's score for what a reply avoids went from 140 to 153 of 156.

The Edit action had the same kind of hole. Its check only looked at the opening's first words, and in my test it let through all 16 cut openings and all 48 swapped ones. Now it matches the hazard's full opening and gets 144 of 144 test cases right.

Known limits

  • On two leads (L019 and L052) the key and the prompt disagree, and I left both as they are.
  • Two others (L034 and L055) drop the customer's past job on every call.
  • The judge misread 5 calls in run 6, so a difference of a few calls between runs doesn't mean much. One run can't tell me whether the facts dip in run 6, from 122 to 115, came from the floor change.
  • Nothing is sent, and there's one approval so far, so I have no approval or edit rates.
  • The held-out sets are small: 8 leads, then 8 safety leads.

What's next

The next fix is a better floor, because the classifier has matched the key on every label I've measured since v2. A second version of the floor gets all 56 right on the leads it was written from, but only 8 of 12 hazards and 9 of 12 lookalikes on the blind set. I want a bigger blind set before I trust it. After that comes sending, behind the same approval step, and letting my orchestrator agent call the approval actions.

How I built it

Built with help from LLMs, mostly Claude. Claude Code did most of the typing on my laptop, and Claude in the desktop app drove the browser on Foundry. I decided what to build, how to test it, and what counts.

Next case study Research agent → A brief where every sentence cites its source.