Danil Sharov - ~/portfolio/cases open for projects

danil@agent:~/portfolio$ cat cases/ai.md

AI inside a product: three versions of one task

Cross-cutting work · analysis of uploaded documents · tested on a live product with paying users

You can plug in an AI model in a day. The trouble starts later: the model writes things that are not in the data, gives different answers on the same data, and you find out what it cost from the bill at the end of the month. I solved the task of turning documents uploaded by a user into a coherent analysis with conclusions in three versions, and each one came out cheaper, more complete and more predictable than the one before.

  1. 01
    One request for the whole document

    The fastest way to show a result: the model gets the whole document and returns finished text. The text looks convincing, and that is the danger: there is nothing to check it against, and two runs on the same data give two different conclusions. If people make decisions based on that text, this approach does not work.

  2. 02
    The work split into steps with checks

    The steps: build the picture, make a plan, back it with references to external sources and check those references against the list of sources actually retrieved. The check filtered out made-up sources, and they no longer reached the user. The main problem remained: the last step only saw a summary of the previous ones, it did not have the original data, and the model filled the gaps on its own. It went as far as advising the person to do something they had done a week earlier, even though that was in our database.

  3. 03
    Code collects the facts, the model only explains

    First, plain code puts all of the person's data into a fact table and gives each fact an ID. Every claim the model makes must reference such an ID, and code drops claims without a reference. The analysis runs as about fifteen independent passes by topic, and code checks each finding separately. At the end it checks coverage, so that no abnormal value in the data gets lost unnoticed.

# what it gave

  • 5-7x cheaper. One analysis cost $0.18-0.24, now about $0.04. The model no longer has to rebuild the picture from a summary, so I replaced the expensive model with a cheap one, and quality did not drop.
  • More complete. A domain expert put together a reference list of findings, and the current version covers 23 items out of 24. The previous one lost whole topics from run to run: the same finding was the main one in one run and not mentioned at all in another. You could only notice that by reading two reports in a row.
  • Verifiable. Code finds errors by comparison: it sees on its own a claim without a reference to a fact, and an abnormal value nobody addressed. This needs neither a human nor another AI model on top.

# so that it can be managed

Models, providers, limits and the maximum price of one analysis are moved into settings and changed from the admin panel without deploying a new version. A change is first turned on for one person, then for everyone, and it can be rolled back with one click. Every model call goes into a log with its actual cost, and spending per user is visible on a separate screen. Once an hour an automatic check looks at whether the provider got more expensive and whether it responds at all. You see AI spending as an ordinary expense line and can cap it in advance, before the bill at the end of the month.

What carries over to your project

  • Code prepares the data for the model, so there is something to check its answer against
  • The answer is checked in a separate step: numbers, references, completeness
  • The model and provider are switched in settings, without code changes
  • A spending cap and a cost log exist from day one, before the first bill
  • Key numbers are calculated with arithmetic, without the model, so the same input gives the same answer

danil@agent:~/portfolio$ ls cases/

# client work

# side projects