Devoured - April 29, 2026
AI rewards strict APIs (4 minute read)

AI rewards strict APIs (4 minute read)

Tech Read original

Strict, typed APIs give AI coding agents tight feedback loops that reduce debugging time and token costs compared to loose, magic-string-based systems.

What: Drupal founder Dries Buytaert argues that the platform's decade-long shift from loose, magic-string hooks to strict, typed APIs (using attributes, schemas, and service containers) is now paying dividends for AI-assisted development, as demonstrated at DrupalCon 2026 where AI tools migrated sites in hours.
Why it matters: The architectural choices platforms made years ago—Drupal betting on strict APIs despite painful breaking changes, WordPress prioritizing backward compatibility—now directly impact how efficiently AI agents can generate and debug code, turning what was a developer preference into a measurable cost difference.
Takeaway: When designing APIs today, prioritize explicit type checking, validation, and structured feedback over convenience or backward compatibility—AI agents will work more efficiently with your platform.
Deep dive
  • AI agents excel at handling complexity but fail when APIs provide ambiguous feedback, creating silent failures that require trial-and-error debugging
  • Magic-string hooks like mymodule_user_login in Drupal or string-based add_action() in WordPress fail silently when misspelled, with no errors or warnings in logs
  • Loose APIs shift costs from upfront boilerplate to later debugging, a trade-off that made sense for human developers but backfires with AI agents
  • Drupal 8 (2015) introduced Symfony's strict routing and service containers, breaking backward compatibility but establishing typed interfaces that static analyzers and IDEs can validate
  • Drupal 11.1 added attribute-based hooks like #[Hook('user_login')] on registered services, making bindings explicit and type-checkable instead of convention-based
  • Multi-year YAML validation efforts catch missing keys, invalid values, and broken references before save time, giving agents precise error messages pointing to exact fields
  • At DrupalCon Chicago March 2026, AI coding tools successfully migrated a Lovable-generated site into Drupal in hours by following the strict API chains
  • WordPress chose backward compatibility over API strictness, maintaining platform stability but preserving looseness that now increases AI debugging costs
  • The feedback loop quality directly impacts token consumption: precise errors mean fewer retries, less guessing, and lower costs per task
  • What was previously a stylistic debate (strict vs. loose APIs) is now a quantifiable speed and cost difference measurable in tokens and development time
  • Platforms that invested in strictness before AI agents existed now have an unexpected competitive advantage in the AI-assisted development era
Decoder
  • Magic-string hooks: Function naming conventions where the system matches functions to events by parsing string names, with no compile-time validation
  • Service containers: Dependency injection systems that manage object creation and wiring, enabling type-checked connections between components
  • Static analyzers: Tools like PHPStan that examine code without running it to detect type errors, undefined variables, and other bugs
  • Attributes: Modern PHP syntax (like #[Hook()]) that attaches metadata to classes and methods, making conventions machine-readable and enforceable
  • Tight feedback loop: The time between writing code and receiving precise error information, critical for both human and AI debugging efficiency
Original article

AI agents don't struggle with complexity. They struggle with ambiguity. Strict APIs are now an important advantage.

An astronaut explores a surreal landscape beneath rainbow-colored planetary rings, symbolizing the journey into AI's transformative potential for Drupal.

Every framework's API surface sits on a spectrum, from strict (typed interfaces, schemas, service containers) to loose (string keys, naming conventions, untyped hooks). Strict APIs cost more upfront: more boilerplate, more to learn before writing code. Loose APIs shift that cost later: more ambiguity, more reliance on naming conventions, and more bugs that are harder to detect and fix.

AI changes who pays. Boilerplate and learning curves don't slow agents down. What slows them down is missing feedback: code that runs but does the wrong thing, errors that don't point to the cause, conventions that have to be guessed. Magic-name binding, untyped hooks, unvalidated configuration, and conventions the code doesn't enforce produce exactly those failure modes.

Magic strings break the loop

For example, both Drupal and WordPress have long used magic-string hooks. In Drupal, you write a function like mymodule_user_login. WordPress uses a related pattern: a string action name passed to add_action(). In both cases, the binding is a string the language can't validate.

Get the name wrong and the system silently skips your code: no error, no warning, nothing in the logs. The function just sits there, unloved.

The signature is a convention, not a contract: the documentation says the user_login hook receives a $user object, but nothing enforces it. To your IDE or a static analyzer like PHPStan, it's just a function. They don't know it's wired into the platform's login flow, so they can't warn you when it's wrong.

A typed alternative makes the binding explicit. With a PHP attribute like #[Hook('user_login')] on a registered service, the class must exist, the method signature is type-checked, and the container wires the dependencies. IDEs, static analyzers, and AI coding agents can follow the chain from the attribute to the implementation.

For AI agents, this keeps the feedback loop tight instead of turning it into trial and error. That means they can move faster, spend less time debugging, and use fewer tokens.

At DrupalCon Chicago this March, AI coding tools migrated a Lovable-generated site into Drupal in hours. The strict APIs kept the agent on track.

A bet made before AI existed

This didn't start with AI. Drupal 8, which we shipped in 2015, introduced Symfony's routing, services, and event dispatcher, replacing large parts of the procedural hook system. Since then, we've kept reducing magic hooks. The attribute-based approach (#[Hook('user_login')]) landed in Drupal 11.1 and helps remove more of the remaining procedural-only paths.

Hooks aren't the only place Drupal has been getting stricter. Drupal stores a lot of configuration in YAML, which was one of the loosest parts of the system. A multi-year validation effort has been tightening that.

When an agent generates a content type definition or editor configuration, validation catches missing keys, invalid values, and broken references before anything is saved. The agent gets a precise error pointing to the exact field, instead of a runtime failure. That tight feedback loop is what makes Drupal a strong CMS for AI-assisted development.

Drupal made this bet early, and it was painful. The Drupal 7 to Drupal 8 transition broke backward compatibility and took years to recover from. But it left the platform much stricter. More than ten years in, we're still making Drupal stricter.

Meanwhile, WordPress made a different bet, prioritizing backward compatibility over stricter APIs. That kept the platform stable for a long time. It also kept the looseness.

Those trade-offs now determine how efficiently AI agents can work with each platform.

What was style is now speed

What used to be a stylistic choice is now a speed and cost problem. Loose APIs mean more debugging and guesswork. Strict APIs mean faster, more precise feedback. This was always true for humans. It's now also true for AI agents. But today that cost shows up in tokens.