Work · PharmaSecure

Find counterfeit medicines before they find patients.

How a problem raised in one client meeting became the counterfeit intelligence layer now running on PharmaSecure's platform.

See psAnalytiQ live at PharmaSecure ↗
The bet
Judge the scanners behind a code before the code itself, and make every flag explain itself in a sentence a compliance officer can read.
What I passed on
A pure machine-learning classifier. Labelled fraud barely existed to train it on, and in pharma an alert that cannot account for itself is not actionable.
What would have proved me wrong
Compliance teams needing us to explain a flag before they could act on it, or the rules missing what the model later caught.
What happened
About 90% less time to surface a suspect code in testing, and in production today as psAnalytiQ on PharmaSecure's platform.

PharmaSecure serializes medicine packaging. Every pack carries a unique code, and anyone holding a strip can verify it against the record to establish that the product in their hand is genuine. Billions of packs carry it, for some of India's largest pharmaceutical manufacturers.

A code returned verified for its first three scans and over-verified thereafter. One code, one answer, assessed in isolation.

I came to PharmaSecure from two years of research at CSIR-CSIO, and this is where research turned into product: the same habit of learning what normal looks like and flagging what breaks it, but now with a client in the room and a patient at the end of the supply chain.

It started in a client meeting

A top Indian manufacturer was describing a problem. Counterfeits were turning up across the country, and codes on its packs had been verified again and again. Not twice, not a dozen times. From around a hundred to three thousand times. It had become a real headache, because they could see the symptom and had no way to see the pattern behind it.

The scale is what makes that figure impossible. A batch carries roughly forty thousand unique codes, of which only about 2 percent are ever scanned at all. A single code reaching twenty or thirty verifications already exceeds anything a shelf and a customer can account for. Three thousand is not an enthusiastic patient. It is one authentic code reproduced across a great many counterfeits, each of them returning genuine to the person holding it.

I picked the problem up from that meeting and took it on myself. The logic across the industry could not help. A code was verified for its first three scans and over-verified after that, so the fourth scan and the three-thousandth earned the same word, and each code was judged alone.

What was at stake

In pharmaceuticals a wrong call costs either way. A counterfeit that goes unnoticed can reach a patient. And a false accusation does real damage of its own: tell a consumer that a code might be counterfeit when it is not, and you break their trust, and you may start a story that a manufacturer is selling counterfeit medicines.

My mission was to stop counterfeits from reaching consumers. That meant never just catching more. It meant being right, being able to show why, and being careful about who hears it first. Much of what follows is that care.

Built for many manufacturers, not one

I did not want to solve this for one manufacturer. Several of the very large manufacturers were on the platform, and the aim was a white-label solution that any of them could switch on.

The catch is that every manufacturer's supply chain and distribution is different. Within one manufacturer, each medicine moves differently too, and the time between a code being printed and its first scan varies. One fixed set of rules would be wrong for most of them. So I took a hybrid approach.

The first half is an algorithm that learns the scan pattern of each manufacturer and each medicine, and flags what departs from it. The second half looks for what cannot happen at all, such as the same code scanned in two states hundreds of kilometres apart within days. Those rules need no history, which is what lets a new manufacturer start on day one.

Where the signals came from

I chose the signals by asking three questions. How was the manufacturer already catching counterfeits? What did we capture about every scan? And what would turn an insight into something a client could act on?

That gave families of signals. How different medicines from the same supplier move. How different batches move. How each code behaves, and the pattern of its scans. How codes from the same batch differ from one another. And which IP addresses and phone devices were scanning abnormally.

What I got wrong first

My first thought was that the data on the codes themselves would be enough. It was not. Even normal scans were sometimes showing up as malicious codes, and an alert system that cries wolf is worse than none.

So I took another approach. Every scan carries metadata, including the IP address and the phone device it came from. I started analysing those too. Looking at how a code behaves together with the addresses and devices scanning it is what gave a firm answer on whether a code was malicious.

Interrogate the scanner, not only the code

The productive shift was to stop asking whether a code looks wrong and start asking who has been scanning it. A counterfeiting operation does not present as one suspicious code. It presents as a handful of devices and networks moving through thousands of them, in territories the genuine consignment never reached, at hours when no pharmacy is open.

So the system maintains a lifetime history for every network address and device it has encountered, and adjudicates those before it considers any individual code. Volumes no legitimate seller generates. Several moderate signals arriving in concert. And the pattern that proved most telling: a scanner that surfaces, works through a tranche of codes and vanishes within days, which no volume threshold on its own would ever register. A code touched by a scanner already known to be compromised is flagged outright, without recourse to a model. Provenance of that quality outranks anything inference can offer.

Rules a compliance officer can read

Each code is then characterised across more than 20 signals: the geographic separation between verifications, how many states it surfaced in simultaneously, how much of its life occurred in the first week after manufacture, activity in the small hours, concentration on a single device, and the interval between manufacture and first appearance, where a negative value means the code was verified before the medicine existed.

Those signals feed rules stated in plain language. Implausible distances between verifications. Several states at once. Some of them are dispositive on their own. Others are inconclusive individually and damning in combination, so they accumulate and trip as a group.

The decision I would defend hardest came next. Where there was no labelled fraud to learn from, the rules became the training data. Domain knowledge was encoded as supervision, and the models learned to generalise beyond it.

A hybrid that learns two ways

Rules can only catch what somebody anticipated. Two models sit behind them, selected for opposing reasons.

The first is a gradient-boosted tree ensemble, trained on the labelled population. It suited the problem because the signals are counts, distances and ratios on entirely different scales, to which trees are indifferent; because it reads interactions rather than features in isolation; and because the class balance is severe enough that rare positives must be weighted heavily, or the model settles on the trivial solution of declining everything. It returns a probability rather than a verdict, which is what allows a threshold to be negotiated openly with a compliance team rather than asserted at them.

The second is an isolation forest, given no labels whatsoever. It infers the shape of normal from the population itself and reports how far a code sits outside it. That matters because counterfeiting is adversarial. Tactics change, and a system that knows only the patterns already codified begins to degrade the moment somebody invents a new one. The anomaly detector is what registers a code that violates no rule and still does not belong.

Neither is trusted in isolation. The two scores resolve into a single risk figure.

Making it work at scale

The scaling problem here is not throughput. It is that normal is a different distribution for every manufacturer. An analgesic sold through every chemist in the country and a specialist therapy shipped to forty hospitals generate entirely different verification behaviour, and a model trained on the first and pointed at the second would raise alarms about nothing at all. Each client therefore carries its own trained pair, versioned jointly against the precise rule set they learned from, so that inference can never run against rules a model has never seen. I did not assume one model for all. For each manufacturer we tested which model fit it best.

That arrangement is also what makes a new client viable on day one. The rules carry the system while there is no history to learn from, entity histories accumulate as verifications arrive, and the models are trained once a population exists worth learning from. The intelligence grows into the account rather than being a precondition for it.

Every alert accounts for itself

In pharmaceuticals an alert that cannot account for itself is not actionable. Somebody has to act on it: dispatch an inspector, write to a distributor, place it in front of a regulator. So every flag carries its reasoning in a sentence a compliance officer can read. Elevated verification count. Multiple distinct devices. Implausible geographic spread. Because the models are versioned against the rules they learned from, any alert can be reconstructed against what the system believed at the moment it fired.

It runs in real time. As soon as a code is scanned, it works out whether that code has been abused, and the result is reflected on the client's dashboard straight away, so the client can act while it still matters. Each scan is judged against everything already known about that code and the scanner behind it.

Who sees an alert

Alerts go to the manufacturer and nowhere else. They are never shown to the person holding the pack. Telling a consumer that a code might be counterfeit, when it is not, would break their trust, and could turn into a story that the manufacturer is selling counterfeit medicines. That was a deliberate, preemptive choice.

Because an alert can still be wrong, every one carries the data that explains why it was raised. The manufacturers' own teams reviewed them and told us whether each insight was right or wrong, and that feedback shaped what we built.

How we knew it worked

One of the manufacturers already had a set of codes it knew for certain were counterfeit, which it had caught earlier. The supervised model was built on those known codes, and they were also where we validated and tested it. The unsupervised model was built separately, with no labels. The two were then combined into the hybrid.

Then it went live. The manufacturer acted on what PS AnalytIQ raised, and those alerts turned out to be fraud. That is how we know it worked.

What it does now

It ships as psAnalytiQ, the intelligence layer on PharmaSecure's platform. In testing it reduced the time to surface a suspect code by roughly 90 percent against reviewing codes individually after the fact, and it converts an undifferentiated mass of verifications into a ranked caseload: reasoning attached, hotspots mapped, repeat offenders named.

What mattered most was what the client could now see. The manufacturer had visibility into how the counterfeiting was actually happening. It put a crackdown in place, and has since carried out several busts of illegal manufacturing units itself. Those results are the manufacturer's. The visibility behind them was the product.

Making the copy worthless

Detection has an inherent ceiling. However early psAnalytiQ raises its hand, the counterfeit has already been printed, distributed and in some cases dispensed. The other half of the answer is to make copying the code worth nothing in the first place.

Serialization establishes that a number is valid. It cannot establish that the number belongs to the pack it is printed on, which is precisely how one authentic code comes to sit on thousands of counterfeits. Non-clonable approaches bind the code to something no counterfeiter can reproduce: a mark whose structure is random at a scale nobody governs, including the press that produced it. Capture it at manufacture, verify it in the field, and a reproduction fails, because it carries the image and not the physical disorder beneath it.

I initiated that programme and drove it end to end, and it is the work I would put forward if someone asked whether I can carry an idea from the literature into something that exists. It began as a literature review and an assessment of what the field had already attempted, became a product definition, and then the logic and the algorithms underneath it. The pilot is finished and the technology is now in its initial launch. The methodology is under patent review.

The difficult problem is not the physics. It is tolerance. Two captures of the same mark are never identical, because the second is taken on a consumer handset, off axis, under pharmacy lighting, on a pack that has spent a week in somebody's pocket. So the governing question is how much divergence still constitutes the same mark, and where that boundary sits. Set it too tight and a pharmacist is telling a patient that their genuine medicine has failed authentication. Set it too loose and the mechanism is ceremonial. That boundary is a product judgment as much as a technical one, and it is where most of my time went.

Asking the data in plain English

Separately, I built a natural-language query layer for analysts, so that a question could be posed in plain English rather than assembled as a query. Building it in-house was a deliberate constraint: pharmaceutical supply-chain data is not material to hand to a third-party model, and nothing needed to leave the network for an answer to come back.

The other half of the job

Counterfeit intelligence was one thread. The other was the product authentication business itself. I was the key person for the client relationship with three of India's five largest pharmaceutical manufacturers, the person both sides called when something required a decision, and I made sure their projects and products were delivered on time. Their serialization projects went out without error, which is the only acceptable standard in pharma, and the people I worked with there can vouch for it.

I also built the company's inventory management system from scratch, covering the full stock lifecycle the serialization business depends on. It went live in January 2025 and automates operations across six departments, for under a quarter of the original budget. It is still in use, it is the least glamorous item on this page, and it is among the most used.

The part I owned

My mission was to stop counterfeits from reaching consumers. I took the problem on from that meeting, and I was both the product manager and the engineer on it, so I built it end to end myself. I changed the question, from judging codes one at a time to judging the scanners behind them. I designed it as a white-label product that learns each manufacturer's normal, because no two supply chains are alike. I made every alert carry its reasoning, so the manufacturer could check it and act on it. And I stayed in the room with the client throughout.

What it taught me

Pharma taught me respect for process. The industry is exacting about documentation and procedure, and I came to read that discipline not as bureaucracy but as the thing that makes trust auditable. The model was the easy half.

You made it to the bottom. Most people don't.

If you're building something interesting, I'd like to hear about it. If you only want to talk roller hockey, that works too.

Or write toparthkhungar33@gmail.com

© Parth Khungar 2026