
PostHog has replaced its ANTLR-based SQL parser with an AI-written Rust implementation that it says runs 454 times faster on production queries. More strikingly, the project took a couple of days rather than the months typically associated with rewriting a mature parser.
The company’s Rewritten SQL parser is a predictive recursive-descent parser with a Pratt expression core. According to PostHog’s announcement on LinkedIn, it was written almost entirely by Claude and produces the same output as the previous parser, including source positions.
This is not primarily a new analytics feature for customers. It is an infrastructure change, and a useful case study in how AI-assisted development can alter which internal engineering projects are economically viable.
Why PostHog Replaced ANTLR
PostHog’s old parser used ANTLR, a widely used parser generator. With this approach, engineers define a grammar, ANTLR compiles it, and the resulting system walks a graph at runtime to recognize and interpret queries. It is flexible and avoids implementing all parsing logic by hand, but PostHog says the runtime overhead made it slower than a purpose-built parser.
The replacement uses recursive descent, where parsing functions directly represent parts of the SQL grammar and predict which rule should be applied next. A Pratt parser handles expressions, an established technique for processing operators with different precedence and associativity.
Hand-written parsers can be fast, but historically they have also been expensive to build and maintain. SQL contains numerous edge cases, and parser mistakes can change the meaning of a query rather than simply produce a visible error. That combination often makes a generated parser the safer engineering trade-off.
AI changed the cost side of that calculation for PostHog. The company said engineer Robbie McLachlan completed the rewrite in a few days, with Claude generating most of the Rust implementation. The fuller technical write-up frames the result less as proof that AI can write parsers and more as evidence that previously deferred optimization work can now become practical.
Testing Against an Oracle
Generating code quickly was only one part of the project. PostHog still needed to establish that the new parser behaved like the production-tested implementation it was replacing.
The team treated the old ANTLR parser as an oracle, effectively making its output the source of truth. Queries were processed by both systems, and each disagreement became a test case. PostHog combined that comparison with property-based testing and real production query logs, allowing the test suite to uncover unusual inputs faster than engineers could enumerate them manually.
The validation covered more than whether a query parsed successfully. PostHog says the replacement produces identical output down to source positions, the location information used to connect parsed elements to their original text. Preserving those details matters for error reporting, query tooling and any downstream system that expects the parser’s existing structure.
The reported 454x improvement applies to production queries tested by PostHog. The company did not publish broader benchmark details in the supplied announcement, so the figure should not be interpreted as a universal speedup for every SQL workload.
For small product teams, the broader lesson is about workflow rather than parser architecture. AI can lower the initial implementation cost of specialized infrastructure, but confidence still comes from deterministic checks, representative production data and an existing reference implementation. Without that verification layer, a fast rewrite could simply produce incorrect results faster.
The work also expands PostHog’s use of AI beyond customer-facing analysis features such as Replay Vision for finding friction in session recordings. Here, the model is being used as an engineering accelerator behind the product, while conventional testing determines whether its output is safe to ship.
Frequently asked questions
What is PostHog Rewritten SQL parser?
It is PostHog’s new Rust-based system for parsing SQL queries. It replaces an ANTLR-generated parser with a predictive recursive-descent design and a Pratt expression parser, while preserving the previous parser’s output and source-position information.
How much faster is the new parser?
PostHog reports that it is 454 times faster on the production queries used in its testing. The announcement does not provide a wider benchmark breakdown, so performance may vary across other query sets.
How did PostHog verify the AI-written parser?
The previous parser served as an oracle, with both implementations run against the same inputs. Differences became regression tests, while property-based testing and production query logs generated additional edge cases.
Sources
1 checkedHow we cover tool news: Create With's tool desk drafts these reports with AI from the sources listed above and checks them against those sources before publishing.





