The assistant inside CogniPrep Assess answers questions about a hiring team's roles and candidates, and can propose changes such as moving people on or sending an email. Wiring a model to tools is the part every tutorial covers. This post is about three things around it that I only learned by watching it run: how to draw half-written markdown, why it never changes anything by itself, and why a reply cannot contain a link you did not expect. You can see what it is for on how it works, and the demo page shows it running.
Half a reply is not valid markdown
The reply streams in a few characters at a time. If you hand each partial string to a markdown renderer, you see **bold with its asterisks, a link with half an address, a table whose first row is a line of pipes, and then it all snaps into shape a second later. It looks broken, every time.
So there is a small pure function between the stream and the renderer, healMarkdown, that finishes or hides the unfinished tail so every intermediate state looks like the finished one would:
- emphasis, inline code and strikethrough are closed
- a half-written link shows only its words
- an open code fence is closed, and a half-typed closing fence is hidden
- a table is held back until its header and separator rows exist, then grows one row at a time, never showing a row that is still being typed
- a lone marker at the very end (
**,#, a half-typed|) is hidden
I did not write the inline part. An existing library, remend, handles emphasis and links. The block-level cases around code fences and tables were the ones I had to write, and the table is the interesting one. A table is three states, not one: a header row alone is just text that happens to contain pipes, so it is hidden until a line that could become a separator arrives. Once a separator exists, a row is shown only when every cell is present and closed. Anything starting with a pipe but with no separator beneath is left alone, because it was never a table.
Being pure matters here. It takes a string and returns a string, so the tests are a long list of "this exact partial input gives this exact output", and it runs in the browser with no server round trip.
A second function, splitBlocks, cuts the reply into top-level blocks (paragraphs, lists, tables, code, quotes). Finished blocks are drawn once, and only the last one is redrawn as words arrive. A blank line inside a list does not end the list if the next line is another item, so a loose list stays one list. Without that, a long answer re-renders its whole self on every token.
It proposes, a person decides
Every tool that changes data or emails someone only prepares the change. The member sees a card with what will happen and presses confirm or cancel. The rules are small, and each one closes a hole:
- Confirming checks the person's permission again at that moment, not when it was proposed. A viewer cannot launder a change through a colleague's chat, and a role that was reduced in between is respected.
- An action works once. Confirming moves its status from pending to confirmed in a single conditional update, and only the request that wins that update runs it. Two clicks, or two tabs, do it once.
- An action expires after 24 hours. A card left open overnight is not a loaded gun.
- Each chat belongs to the member who started it, and only they can delete it.
The standing instructions say the same thing to the model, in plain words: never claim a change is done until you are told it was confirmed, and people decide on candidates, so never propose a hire or decide who is rejected. That is a second fence. The first is the code, which would hold even if the model ignored the words.
When a confirmed action fails, the card says what happened, in the member's terms. A failure we expected shows its reason. One we did not says it may not have finished and to check the page before trying again, because that is the honest state.
A reply is untrusted, because it quotes strangers
This one is easy to miss. The assistant reads CVs, application answers and notes, and those are written by candidates. A reply can quote them. So a candidate can, in principle, write text that makes the assistant produce a link.
Links in a reply therefore go through one function that decides what a link may be:
- a path inside the product (the app and the public job pages) opens in place, made relative so it works on any address the app is served from
- our own other pages, such as help, open in a new tab
-
anything else is not a link at all. The words are shown as plain text. That covers other websites, email addresses, addresses with a username in them, protocol-relative
//paths and odd schemes.
The assistant's instructions say not to link elsewhere, but I treat that as a request, not a guarantee. The renderer is where it is enforced. Text from candidates is described to the model as information and never instructions, and the same distrust applies to what it says back.
Remembering without the provider
Each turn is the member's message, then as many rounds of tool calls as the model asks for, up to a limit of eight, with the last round allowed to write only. Every message, call, result and proposed change is stored as it happens, so a reply cut short by the member or the network is still there when the thread is reopened. The provider is told to keep nothing, and each new turn is rebuilt from what we stored. The history list groups chats under Today, Yesterday, Previous 7 days and Older, by the member's own midnight, and its search folds accents so "Zoe" finds "Zoë".
What I would tell someone starting
Build the three fences before the clever part: heal the stream, make every change a card, and decide in code what a link can be. None of them involves the model. All of them are what make it safe to put in front of a hiring team.
If you want to see the assistant in the product, book a demo. The way we treat candidate data around it is described on the fairness page and in the data processing summary.
Top comments (0)