> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt # Classifying rows with AI The `jev()` and `decide()` SQL functions use a small AI model to answer a question about each row of a query. You can use them to tag support messages, sort feedback into categories, or flag events that match a description, without writing the rules yourself. Pass the text to evaluate and a question. By default, the function returns the probability (from 0 to 1) that the answer is yes: SQL [Run in PostHog](https://us.posthog.com/sql?open_query=SELECT%0A++++properties.%24message+AS+message%2C%0A++++jev%28toString%28properties.%24message%29%2C+'Is+this+person+asking+for+a+refund%3F'%29+AS+refund_probability%0AFROM+events%0AWHERE+event+%3D+'support+message+sent'%0ALIMIT+100) ```sql SELECT properties.$message AS message, jev(toString(properties.$message), 'Is this person asking for a refund?') AS refund_probability FROM events WHERE event = 'support message sent' LIMIT 100 ``` To pick one label from a list, pass `choice`. The result has the chosen label, the probability of each label, and a confidence score: SQL [Run in PostHog](https://us.posthog.com/sql?open_query=SELECT+result.choice+AS+topic%2C+count%28%29+AS+feedback%0AFROM+%28%0A++++SELECT+jev%28%0A++++++++toString%28properties.%24message%29%2C%0A++++++++'What+is+this+feedback+about%3F'%2C%0A++++++++choice+%3A%3D+%5B'pricing'%2C+'bugs'%2C+'feature+request'%2C+'other'%5D%0A++++%29+AS+result%0A++++FROM+events%0A++++WHERE+event+%3D+'feedback+submitted'%0A++++LIMIT+200%0A%29%0AGROUP+BY+topic%0AORDER+BY+feedback+DESC) ```sql SELECT result.choice AS topic, count() AS feedback FROM ( SELECT jev( toString(properties.$message), 'What is this feedback about?', choice := ['pricing', 'bugs', 'feature request', 'other'] ) AS result FROM events WHERE event = 'feedback submitted' LIMIT 200 ) GROUP BY topic ORDER BY feedback DESC ``` `decide()` works the same way and also takes a `model` argument, either `'jeeves'` (the default, and what `jev()` uses) or `'jevk5'`. For example, `decide(message, 'Is this spam?', model := 'jevk5')`. ## Where your data goes PostHog builds and hosts both models. They run on PostHog's own servers in the same region as your project, so your data is not sent to a third-party AI provider such as OpenAI or Anthropic. If your project is in the EU, the evaluation also stays in the EU. Jeeves, the default model, is open source. Its code, training data and benchmark results are in the [PostHog/jeeves](https://github.com/PostHog/jeeves) repository. ## Limits - Use the function as a named column in a `SELECT`. To filter or sort on its result, wrap it in a subquery and filter in the outer query. - Each query has two limits, and the error tells you the current value of whichever one you hit: - **Rows:** the number of rows a `SELECT` can send to an AI function. Add a `LIMIT` to stay under it. - **Evaluations:** the total across the whole query. Each AI column on each row counts as one, so two AI columns over 500 rows use 1,000 evaluations. A `SELECT` without a `LIMIT` reserves the full row limit for each AI column, so add a `LIMIT` when you use more than one. - Each input can be up to 8 KiB of text. Convert other types with `toString()`. Empty (`NULL`) inputs are skipped. - Identical inputs with the same question are only evaluated once per query. ## Pricing Each evaluation uses [PostHog AI](/docs/posthog-ai.md) credits and appears under PostHog AI on your billing page. If your organization runs out of credits, the query stops with an error that says so. ### Still have questions? Ask PostHog AI ### Was this page useful? HelpfulCould be better