The contract analysis tools I built on Legaliser's product team, 2023 to 2024
Written by Shahzaib Shoaib, founder and lead engineer
Before Zaibex, our founder was a senior engineer on the team behind Legaliser, an AI contract drafting and review platform. His share: the AI analysis tools, schema-checked output, jurisdiction-aware prompts and the analysis screens.

- Client
- Legaliser (team product, before Zaibex)
- Our role
- Senior engineer on the product team (before Zaibex)
- Industry
- Legal · LegalTech
- Services
- AI Contract AnalysisFull-stack
- Timeline
- May 2023 to October 2024
Four files on a Tuesday in November
On Tuesday, 28 November 2023, I added four files to the Legaliser backend: getDocInsights.js, getDocWeaknesses.js, optimizeContract.js and optimizeWithRecommendation.js. Each one took a contract a user had uploaded, sent it to an OpenAI model with a prompt, and handed the answer back to the app. One pulled out insights about the document. One listed its weak points. The last two proposed an improved version, the second of them working from a specific recommendation.
This was before Zaibex. Legaliser was an AI contract drafting and review platform, built by the product team at my previous employer. I was a senior engineer on the product team, one of about thirteen people who committed to it. Between May 2023 and October 2024 I made roughly 683 commits to the frontend and 116 to the backend. One colleague made more than I did in both repos.
So this page is about my share of a team product. Teammates edited all four of those files later, and I stayed the top committer on each. Where someone else built a part, I say so.

What was already there
The frontend repo was a month old when I made my first commit on 2 May 2023. It was Next.js 14 on Firebase, with Firestore as the database and Apollo Client on the side. The backend repo came later. Its first commit is dated 26 October 2023, and on the 27th I split its source into separate folders, a commit I titled "separated src folders" with no further ceremony.
The backend ran on Fastify with firebase-admin, Redis at one point, the OpenAI SDK, and pdf-parse and pdf2md to turn uploaded PDFs into text a model could read. LangChain was in there for its PDF loader and text splitter. Puppeteer was in the dependency list too.
A lot of Legaliser was other people's work. The collaborative editor ran on a Hocuspocus and Yjs server. Question-led contract generation asked the user questions and drafted from the answers. A colleague built a separate research service in Python with FastAPI. Teammates built most of the template analysis and reanalysis features. The credit-check logic and the APIs for creating a document from a template were theirs as well. I touched some of those in passing. I did not build them.
Making the model fill in a form
Free text from a model is easy to print and hard to build a screen around. The analysis sidebar needed answers in a predictable shape, every time, whatever the contract said.
On Thursday, 18 April 2024, I added a zod schema for doc insights. The schema defines what an insight looks like, and zod-to-json-schema turns that same definition into the function definition OpenAI receives, so the model answers by filling in typed arguments. The same day I moved doc insights onto gpt-4-turbo. Twenty-five days later a teammate switched it to gpt-4o. By the end, the utilities ran on gpt-4o and gpt-4o-mini.
This is the decision I would defend if someone pushed on it. Models changed under us twice in under a month. The description of what the sidebar expects lived in one schema file, written as code, instead of in a paragraph of prompt text asking the model nicely to return JSON.
The trade-off is the date. getDocInsights.js went 142 days without a schema. I wrote it in November and added the schema in April, and I should have done both on the first day.
The commit only covers doc insights, and I can't point to the same change in the other three files.

A schema proves the model returned the right fields. It can't tell you the clause it flagged is really weak, and I never built the check that could.
Prompts that know where the contract lives
A clause can be fine in one country and a problem in another, so I added jurisdiction to the prompts and then a jurisdiction picker in the upload area (PR #64). The user chooses it when they drop the file in, and it travels with every analysis call after that.
In July 2024, on the 9th, I added the adversarial prompt that sits behind the adversarial chat session. Later came drafting a whole document from a user's own prompt (PR #98, ticket LEG-327). In September and October 2024 I reworked the contract-creation prompts and wrote generateNextPara, which drafts the next paragraph of a contract the user is already writing.
Smaller things too. I added the user's id to our OpenAI calls, so each request can be tied back to an account. My final PR on the project was LEG-377, titled "fix api prompts". Prompt work was never finished while I was there, and that title is an honest summary of it.
What a user saw on screen
You land on a dashboard I helped lay out, with a sidebar you can shrink. You drag a contract onto the upload area, pick the jurisdiction, and the file goes up. When analysis finishes, the contract analysis sidebar shows what came back from those four files. I also made analysis work on blank documents and on templates, so a user could get a review of something before it was finished.
The search dialog on the dashboard (LEG-299) was mine. It searched what was in the interface. There was no retrieval engine behind it, and I want to be clear about that because older copy implied otherwise.
The usage card showing remaining credits was mine; the credit-checking logic behind it was mostly a teammate's.
I moved the analysis variables into Firestore, so they lived in the database and not in code. I also cut some of the releases, with names like "Release 24-36".
The plumbing nobody demos
The blog lived in WordPress, and I connected it to the Next.js app over GraphQL with Apollo. On 15 May 2024 I wrote the Dockerfile for the Uppy Companion server that handled uploads, and I updated the main server's Dockerfile.
What we can't tell you
There are no numbers on this page. Earlier write-ups carried a user count and a speed figure, and neither one has a measurement window, a baseline or a source I can show you. Until one turns up, they stay off.
The schema has a limit I never solved. It proves the model returned the right fields in the right types. It can't tell you whether the clause the model flagged is actually weak, or whether a suggested rewrite still means what the parties intended. A separate meaning check, or a path that sends a doubtful answer to a person, is not something I can find in the git history, so I won't claim it existed. I also have no record of lawyers reviewing the output as a process, so this page doesn't say they did.
If I did it again I would put the schema on all four analysis files on the first day, and I would log how long each contract took to review before and after, so there would be a real number to quote now.
Where it stands
My last Legaliser commit is dated 3 October 2024, and I left that employer the same month. In 2023 I made 225 commits to the frontend and in 2024 another 458. The product has since changed hands and name, and what you find at its old address today is somebody else's work. None of its current features or numbers are mine.
- Next.js
- Firebase
- Firestore
- Fastify
- OpenAI
- zod
- LangChain
On a team product, ask what one engineer can show in the commit history, and judge them on that. Here it is the AI analysis code, a typed schema between the model and the screen, prompt work that kept changing, and the screens people used. What it can't show is a measured result, and saying so plainly beats borrowing numbers that were never counted.

