AI-Driven Book Recommendation Engine with Ollama and OpenLibrary - n8n Workflow

Automate book recommendations using this advanced n8n workflow. It leverages the Ollama LLM to analyze email requests, finds relevant titles via OpenLibrary, and sends personalized recommendation emails.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Reading Clubs and Educators: Automatically suggest books based on member requests or curriculum topics.
Automated Content Creators: Generate relevant content or suggestions for newsletters quickly.
Developers and Automation Engineers: Anyone seeking practical n8n templates integrating self-hosted LLMs (Ollama) with external APIs.
Librarians and Information Specialists: Streamline the process of responding to common genre requests.

Overview

This powerful n8n workflow solves the problem of manually responding to book request inquiries. By integrating a local or self-hosted Large Language Model (LLM) like Ollama with the vast OpenLibrary database, the process is instant and highly personalized. The n8n automation starts when a request email arrives, uses the LLM to intelligently extract the user's intent (e.g., 'fantasy' or 'thriller'), and then fetches a specific, randomly selected book recommendation.

This specific n8n node combination ensures high accuracy in genre parsing, robust error handling for subjects where no books are found, and the final output is a rich, HTML-formatted email. Utilizing this n8n template saves time and provides an engaging, immediate response to user requests, showcasing the power of advanced n8n integrations.

How it Works

The process begins with the designated n8n trigger, the IMAP-based 'Email Trigger – Book Request' node, which monitors an inbox for new messages.


  1. AI Analysis: The raw email content is passed to the 'Analyze Email with Ollama' n8n node. This node, leveraging the Ollama LLM, runs a prompt designed to extract only the requested book types or genres, providing a clean subject term.

  2. Query Generation: The extracted genre is used by the 'Create Book Search Query' n8n node to format the OpenLibrary search URL.

  3. API Search & Validation: The 'Call Book Search API' n8n node hits the OpenLibrary subject endpoint. The workflow then uses the 'Check API Response' n8n node (an If condition) to ensure that books were found. If not, the automation follows the failure path to send an apology email via SMTP.

  4. Random Selection: If books exist, the 'Check Book Name' n8n code node calculates a random offset within the search results to ensure a new recommendation is provided each time.

  5. Detail Retrieval: Two subsequent HTTP Request n8n nodes ('Extract Book Summary' and 'Retrieve Book Details') use the random offset and the book's key to fetch the title, summary, and full description.

  6. Data Enhancement: The 'Enhance Data with Code' n8n node uses custom JavaScript to transform the list of authors into clickable HTML links, enriching the final output.

  7. Final Delivery: The 'Generate Email Content' n8n node compiles the title, description, and author links into a professional email body and subject line. Finally, the 'Send Recommendation Email' n8n node delivers the personalized book recommendation to the user, completing the n8n workflow.

Installation Guide

To set up this n8n workflow, follow these steps:


  1. Import the n8n template: Copy the provided JSON and import it into your n8n instance.

  2. Configure the n8n trigger: Update the 'Email Trigger – Book Request' n8n node with your IMAP credentials to monitor the desired email address.

  3. Set up Ollama: Ensure your Ollama LLM service is running and configured correctly. Update the credentials in the 'Ollama Model' n8n node to point to your LLM endpoint (it uses llama3.2-16000:latest in the example).

  4. Configure SMTP: Update both 'Handle No Book Found' and 'Send Recommendation Email' n8n nodes with valid SMTP credentials for sending emails.

  5. Review Placeholders: Check the toEmail and fromEmail fields in the Send Email nodes and replace placeholder addresses (e.g., [email protected], [email protected]) with your actual target and sender emails.

  6. Activate: Save and activate the n8n workflow to start monitoring for incoming book requests.

Node Details

Email Trigger – Book Request (n8n trigger):
Function: Initiates the n8n workflow when a new email is detected in the configured IMAP inbox.
Key Configuration: Uses IMAP credentials to poll the specified mailbox.

Analyze Email with Ollama (Langchain Agent n8n node):
Function: Connects to the local Ollama instance to analyze the email body (textPlain) and extract the book genre using a highly specific system prompt.
Key Configuration: Uses the llama3.2-16000:latest model and a custom prompt to ensure the output is a clean, lowercase genre.

Call Book Search API (HTTP Request n8n node):
Function: Queries the OpenLibrary API using the genre extracted by the LLM.
Key Configuration: URL dynamically built using https://openlibrary.org/subjects/{{ $json.subject-name}}.

Check Book Name (Code n8n node):
Function: Executes custom JavaScript to calculate a pseudo-random index (retrievebook) based on the total number of search results (workcount), ensuring a different book is picked each time.

Retrieve Book Details (HTTP Request n8n node):
Function: Fetches the detailed description of the randomly selected book from OpenLibrary.
Key Configuration: URL dynamically constructed using the book's key from the previous API result.

Enhance Data with Code (Code n8n node):
Function: Processes the array of authors and transforms it into a clean, comma-separated string of linked HTML anchor tags, enhancing the presentation in the final email.

Send Recommendation Email (Email Send n8n node):
Function: Sends the final, richly formatted book recommendation to the recipient via SMTP.
* Key Configuration: Uses expressions to insert the generated subject and HTML body from preceding n8n nodes.

Related n8n Workflows

Free

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by

The AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.

Featured*