DEV Community

Michael Hairetis
Michael Hairetis

Posted on

Stop writing the function that guesses what messy input means

Every system I have ever built has a function in it that has to make a judgment call from messy input. Which category is this? Did that actually succeed? What kind of failure is this?

The traditional answers are a chain of if statements, a keyword list, a regex, or a lookup table. They are all the same answer wearing different clothes: enumerate the cases in advance and hope reality complies.

Reality does not comply. You ship the regex, it works for a month, then something arrives phrased in a way you did not anticipate and your code confidently does the wrong thing. So you add a branch. Then another. Eventually the function is four hundred lines of accumulated special cases nobody can safely modify, and it still cannot handle a sentence it has not seen.

I stopped writing those, and the mechanism is simpler than it sounds.

Put an HTTP endpoint in front of a real coding agent. Not a model behind an API, an agent: something with a role, a memory, and tools, that reads files and iterates and knows when it is finished. Give it a role name and a prompt, get that role's answer back. Everything upstream believes it is calling an ordinary service and never learns otherwise.

Now the judgment calls become function calls. Things like:

  • Intent. Is this sentence a task to dispatch, a question to answer, or a schedule to create? No keyword matching. It reads the sentence.
  • Schedules in plain English. "Every other Friday at 4pm, but not on holidays" becomes a real cron expression. I never wrote a date-phrase parser and never will.
  • Fulfilment. A job reports success. Did it actually do what was asked, or something adjacent? The standard here is the user's original intent, which is a sentence, not a schema.
  • Root cause. A run fails. Transient network blip or permanently broken source? That is a semantic distinction, not a status code.

The last two could not have been written the old way at all. Not "would have been tedious." Could not. There is no regex for did this satisfy what the person meant.

One important detail: do not lead with the agent. Cheap deterministic checks run first and settle the obvious cases with no round trip. The agent handles what the deterministic layer cannot, and there is a dumb fallback beneath everything. Every verdict is tagged with which layer produced it.

That ordering is the opposite of how people usually reach for an LLM. The model is not there to replace the logic. It is there to handle the residue the logic was always quietly getting wrong.

Full write-up, including what this did to the economics:

https://openred.space/blog/claude-code-as-a-webservice.html

Top comments (0)