Skip to content

Domain-specific language for AI agents: pay for tokens once

View as MarkdownOpen in ClaudeOpen in ChatGPTOpen in Perplexity

The question is copied too. If the chat opens empty, paste it.

On this page
  1. What is a domain-specific language for an AI agent?
  2. Why is free code a weakness for a narrow agent?
  3. How much does a model reading every page cost?
  4. Is the data better when the model writes the parser?
  5. JSON config, cut-down language or your own: which one?
  6. When is it too early for a DSL?
  7. My similar case
  8. Limits of this article

TL;DR

If an AI agent does the same narrow job again and again, like pulling data from similar pages, don’t let it read every page and don’t let it write any code it wants. Let it write a small config in a limited language once, check that config automatically, then run it with no model at all. You pay for tokens once per source instead of once per page. Plain JSON or YAML is enough for most jobs. When you need branching, take a language the model already knows and cut it down, instead of inventing a new one.

I’m Denys, a Forward Deployed Engineer. I build AI agents and automations for small firms. This article is for an owner or a team lead whose AI bill grows with every page, document or record the agent touches. The idea here is not new and not mine, it is older than AI agents. I just see it save money often, so here is how it works and when it does not.

What is a domain-specific language for an AI agent?

A domain-specific language (DSL) is a small language made for one job. You use some every day: CSS selectors pick elements on a page, SQL asks a database, a cron line says when a job runs. None of them can do everything, and that is the point.

For an AI agent it means this: instead of “write any Python you want”, you tell the agent “fill in this format”. In the simplest case the format is a JSON or YAML config with fields you defined. In a bigger case it is a cut-down dialect of a real language, for example JavaScript with no imports, no eval and only the functions you give it.

The agent still does the thinking. It just writes its answer in a language where the number of possible mistakes is small.

Agent costs too high? Let's fix the architecture.

Contact me

Or email me: yes@madsalt.tech

Why is free code a weakness for a narrow agent?

An agent can write any code. For a general coding assistant that is the whole value. For a narrow agent that does one job in your product, it is mostly risk:

  • More room for mistakes. Any language means any bug, including ones nobody thought to test.
  • More tokens. A full script is longer than a config, and the agent writes it again for every new source.
  • Less security. Free code can import anything, call any address and read any file the process can reach.
  • Harder to check and update. Someone has to review each script. When a page changes, someone has to understand code an agent wrote months ago.

A config in a small language turns most of that into one automatic check: does it match the format, does it return the fields you expect, yes or no.

How much does a model reading every page cost?

Here is a simple example with my own numbers, not a benchmark. Say one page is about 10,000 tokens of text and the model writes 300 tokens of data back. On Anthropic’s list price a strong model charges USD 4 per million tokens read and USD 20 per million written, and its smallest model USD 0.10 and USD 0.50 (Anthropic pricing, read 9 November 2026).

Approach Cost per page 1,000 pages a day, 30 days
Strong model reads every page about USD 0.046 about USD 1,380
Smallest model reads every page about USD 0.0012 about USD 35
Strong model writes one config per source USD 0 per page after that one-off, about USD 1.80 per source

The last row assumes one setup session of about 300,000 tokens read and 30,000 written per source. Your pages, models and sessions will differ, so put your own numbers in. Other ways to cut the same bill, like caching, batch and a lower effort level, are in how to reduce AI costs.

Two things stand out. First, with a strong model, per-page reading grows with every page and every run, forever. A config is paid once. Second, the smallest model makes per-page reading cheap, so money alone is not always the reason. The other reason is quality.

Where the model spends tokens. Three ways to get data from many similar pages. Model reads every page: tokens on every page, every run: Each page → Model → Data; Model writes free code once: hard to check, hard to update: Model → Python or TS script → Code review → Runs with no model; Model writes a small config once: checked, then runs with no model: Model → Config in a small language → Automatic check → Runs with no model.
The three approaches compared in this article.

Is the data better when the model writes the parser?

There is published evidence that it can be. The WebLists benchmark (April 2025) has 200 data-extraction tasks from business use cases. Language models with search found 3% of the rows they should have found, and current web agents 31%. An agent that builds a CSS selector and then replays it over similar pages found 66%, and cost about 3 times less per row.

Two caveats. The authors work at the company that built that agent, so these are their own numbers. And a selector is itself a small language, which is exactly the point of this article: the model did better when it wrote a short, checkable answer in a language it already knew well.

There is also a plain practical reason. A model that reads a page can return a value that looks right and is wrong, and nothing fails. A config that stops matching usually fails loudly: a required field comes back empty and the check stops the run.

JSON config, cut-down language or your own: which one?

Go up this ladder only as far as you have to.

  1. A JSON or YAML config. Fields you define, like “list item selector”, “price selector”, “date format”. Most extraction and integration jobs stop here. Vendors now constrain model output to a JSON schema you give them (structured outputs), so the agent cannot even return a config with a missing field.
  2. A cut-down version of a language the model knows. When you need branching, loops or odd cases, a config starts to fail. People then put logic inside strings (“if this field is empty use that one”), and the agent keeps getting the small rules wrong. At that point take JavaScript or Python, and limit it: no imports, no eval, one function for network calls, a short library of ready helpers, and a strict check of the result.
  3. Your own language from scratch. Almost never. The model has never seen it, so you have to teach it in every prompt, and you also have to write the parser, the errors and the docs yourself.

An executable dialect in step 2 means you have to think about isolation: where the code runs, what it can reach, how long it may run. That work is real. It is still less than writing and maintaining a language of your own.

When is it too early for a DSL?

When you don’t know the job yet. If every new source looks different and you are still finding out what the agent needs to do, let it write free code and watch what it writes. The patterns that repeat are the future config fields. Once they settle and the limits are clear, cut the language down.

A DSL is a narrow tool. It pays off on repeated work with known limits: many similar pages, many similar documents, many similar integrations. For a one-off task it is extra work for nothing.

My similar case

For a travel agency I built a package-holiday price benchmark that compares their packages with competitor sites. The collection itself runs with no model in the loop: a scheduler, a browser pool and plain HTTP where a site allows it. The client’s AI agent does not read the pages. It only starts a benchmark through one tool call and gets the results back. On one site, dropping the browser for plain HTTP took collection from 8 to 43 dates a minute. See the travel price intelligence case.

If you pay for a model to read the same kind of page again and again, send me what the agent does and roughly how many pages it reads. We’ll work out together which part can run once and which can run with no model at all. This work falls under web scraping services and AI agent development.

Does your agent pay for every page it reads?

Send me what it does and how often. I'll show you what can run once instead.

Free consultation: a second look at your idea or your app.

Write to me

Limits of this article

  • Example numbers. The cost table uses my assumed page size and setup session, and list prices read on 9 November 2026. Measure your own pages before deciding.
  • One benchmark. The WebLists results come from the authors’ own company, and I know of no independent repeat.
  • No client token bill. The travel case shows a speed number from the commit log, not a token saving; that project never had a model reading pages.

© 2026 Denys Zaichenko. Original article: https://madsalt.tech/blog/ai-agent-domain-specific-language/