New Module: AI Deep Reference

By Jordan , 10 December, 2025
illustration: a robot reading a book

I’m proud to announce my latest contribution to the Drupal AI ecosystem: the AI Deep Reference module.  The purpose of this module is to help populate queries, so an AI can draw an image (or even a video).  It relies entirely on the existing AI ecosystem, and acts as a “glue” with the token module, to provide deeper references than the Token module can on its own.

The module itself is not complicated; it simply hooks into the existing Token architecture, and reads the “description” field from a taxonomy term.  (By default, all taxonomy terms have a description, so you would have to engage in some shenanigans for this module not to work.)

Why Build This?

My motivation was actually a weekly Dungeons & Dragons session.  My friend Jim started these sessions during the pandemic, and Paul has continued to carry the flame.  My job is simple: the soundtrack.  I’m responsible for injecting music into our Discord channel.  But what is music… without a little visual ambiance?  Enter the AI.  I’ve been using OpenAI to generate images for our D&D sessions since Dall-E v2 (that’s ancient, by AI reckoning).

So what’s the problem?  After months of being in the same adventuring party, I’m getting sick of writing the same query over and over.  An armored bear carrying an enchanted flail.  A male elvish archer - because the AI always defaults to female, if you don’t specify.  (I’ll save the editorializing for another day.)

The solution, of course, is Drupal.

In particular, I want an AI generator that “remembers” my adventuring party, the setting, and maybe some additional details.  At the end of 2025, it’s amazing how far the AI ecosystem has come in Drupal.  I was able to build almost the entire stack using community-contributed modules:

  • The AI core module (of course)
  • AI Automators (comes with the AI module)
  • Token
  • OpenAI provider, because ChatGPT is my poison of choice
  • AI Media Image, for integration with the media module

The media module integration is not necessary, but I found it helpful; older implementations had a tendency to fill up my server hard drive, which is… sub-optimal.

My architecture is simple: a content type, a few taxonomies, and a single AI automator.  The automator is the secret ingredient; with it, I can grab the text fields, and generate my own AI query, using the taxonomy terms as variables.

As you’re adding your media field, be sure to add the AI automator.

screenshot of AI Automator in use

The automator query takes plain English instruction, but we will add integration with the Token module.  This lets us grab the taxonomy terms from our other fields, and inject them in our query.

But here’s the limitation: with the Token module, you only get the taxonomy names.  What if you want to add a description?  The token module won’t inject that into your query.

Enter my module: AI Deep Reference.

The premise is simple: it extends the Token module, and allows the AI Automator to read the description on the taxonomy term.

The implementation is simple as well; there’s an implementation of hook_token() which checks for taxonomy terms, and then injects the value of the description field.  You can see the whole thing here: https://www.drupal.org/project/ai_dr

What’s Next?

How about a recipe?  I just described my fancy DnD illustrator; maybe others would want to use it too?  Should I open my own illustrator to the public?  It would have to be ad supported, as those api bills do add up.  What about extending the module further, to work with any field attached to a taxonomy term?  Or other entity types?

I don’t allow comments on my new blog (too many spammers), but if you’ve read this far, let me know what you think!  LinkedIn is always a good choice (I’ll post this blog on my wall).

As always, it feels good to release a module.  Giving back to the community makes my open-source heart go pitter-pat.  (No, really; it’s called the Human Genome Project.)

For now, I’ll leave you with the prompt I used in my AI Automator to generate the image:

You are an illustrating robot, and you need to illustrate a scene from a Dungeons & Dragons adventure.

Setting: [node:field_scene], [node:field_scene:entity:description]

Environment: [node:field_environment]:
- [node:field_environment:0:entity:description]
- [node:field_environment:1:entity:description]
- [node:field_environment:2:entity:description]

Characters: [node:field_characters]: 
- [node:field_characters:0:entity:description]
- [node:field_characters:1:entity:description]
- [node:field_characters:2:entity:description]

Description: [node:field_description]

But, Does It Work?

In order to test this properly, I needed a query that would test the AI’s knowledge, using only references to taxonomy terms.  In my weekly D&D adventure, I play an armored bear named Oopie.  He wields a magic flail (a type of medieval weapon).  Currently the adventure has us on a flying ship, which has taken off and is soaring through the sky, except it’s also haunted (for Halloween).  I’m getting sick of typing all these details into the query every time I want to draw an image for my friends, so let’s see if Drupal can help:

screenshot of Drupal config

I’ve created a node with three taxonomy terms and its own “description” field, not to be confused with the taxonomy description fields.  Anyway the taxonomies capture characters, scene, and environment (eg. night time, full moon).  This is just a test, so I’m going to give the AI a query, and expect it to fill in the details using the taxonomy terms.

My query is simple: “Oopie balances a ball on the end of his nose.” I’m expecting the AI to know that Oopie is a bear, he is wearing armor, and he is standing on the deck of a haunted flying ship at night.  The first few tests were unsuccessful, with hilarious results:

Image
Image

 But once I got my module working correctly, it all slid into place:

Image

Comments

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.