juanazam

juanazam

Using AI as an intent layer for filtering in a Phoenix app

I’ve been experimenting with a small pattern for using AI in apps.
Instead of replacing the UI with a chat, I tried using it to help users build filters.

So a user can type something like: “customers who spent more than $500 in the last 3 months and haven’t ordered recently”

and the app turns that into a struct and runs a normal query (Ecto in this case).

The important part for me was keeping things predictable:

  • the model doesn’t generate queries
  • everything goes through a schema
  • you can still edit the filters manually

Wrote a short post about it:

Most Liked

tfwright

tfwright

We are in the process of beta testing a feature more or less identical to this, although we needed to support fairly complex filters across multiple tables and in some cases with multiple params. We already had a conventional UI built out, and the backend to support the filter logic.

One thing we did was use the existing function and module docs from the filter logic using Code.fetch_docs to build the LLM context. And then we added a bunch more detail and examples to function docs until the LLM was able to reliably return useful data. The filter logic also already had casting/validation so we could just use that. Took some fiddling, but the entire feature only ended up being a thin wrapper around ReqLLM, a context generator that pulled in all the docs, and an endpoint that called out to those and applied the validation and returned the result. And as a bonus we had more general purpose docs than when we started. Turns out a lot of the instructions that help Claude also help human devs.

I maintain a small utility for dumping docs and as a next step I am going to try to use that to extract the “context baking” logic from runtime code.

juanazam

juanazam

Definitely a fun experiment! The challenge of validating the response sounds complicated though :sweat_smile:

Where Next?

Popular in Blog Posts Top

New
brainlid
Livebook was created for machine learning in Elixir but Livebook isn’t limited to machine learning. I found it works really well for docu...
New
brainlid
OTP 26 was released and the Elixir 1.14.4 builds have been updated! Erlang OTP 26 changed how map keys are sorted, or not sorted actually...
New
JEG2
I’m closing out, for now, my series on questions at the heart of development with an analysis of when we need more abstraction. For exam...
New
DevotionGeo
There are 3 main formatters for Erlang which you can use from the command-line, rebar3_format, Steamroller elmfmt. Visual Studio Code’...
New
brainlid
This post asks if we can remove Alpine from the PETAL stack. Can we do everything we need with just LiveView? Also, let’s explore an area...
New
hauleth
I wanted to write down some of the main guides I use when writing Elixir tests, so I have summarised them in blogpost. Furthermore, I th...
New
mudasobwa
Blogged about the motivation and reasoning behind my idea to create yet another FSM library. Long story short: I did it in a proper way :...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
New
New

Other popular topics Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement