Meta Tag Generator Powered by DeepSeek
Summary
I added a DeepSeek-powered meta tag generator to my SEO tools service (continuation of the catalog case study): given a page URL, the neural network outputs title, description, and keywords. The main challenge isn't "asking the neural network" but giving it the right page context and forcing it to return strict JSON. The tool itself gathers context via curl, parses the response with a regex fallback, validates lengths on the frontend, and shares the common paid API protection engine with the AI audit.
Technology Stack
| Technology | Role |
|---|---|
| PHP 8.3 | Microservice, curl context collection, JSON parsing, protection |
| Joomla 6 | CMS, tool page article |
| SQLite | URL cache, quota, rate-limit |
| DeepSeek API | Generation of title / description / keywords |
| Javascript (ES6) | Frontend: form, length validation, highlighting |
Context and Task
The "Meta Tag Generator" tool: the user enters a page URL, and the service generates three meta tags:
- title — up to 60 characters, with the key query at the beginning;
- description — 120–160 characters, with a call to action and keywords;
- keywords — 5–7 comma-separated words.
The requirement is that the tool must understand what the page is about on its own, without asking the user for anything except the link.
Why It's Useful and Why AI Is Needed Here
Meta tags are what appears in the search results snippet. CTR depends on them. Writing them "by the rules" (length, key at the beginning, CTA) is a routine copywriting task that a neural network automates well.
The complexity isn't in "asking DeepSeek" but in giving the neural network the right context: it must generate tags specifically for the content of the given page, not produce a template response.
Pipeline Architecture
flowchart TD
A["User enters URL"] --> B["Context collection (curl)"]
B --> B1["<title> of the current page"]
B --> B2["meta description (if present)"]
B --> B3["meta keywords (if present)"]
B --> B4["<h1>"]
B --> B5["Text fragment<br>(first 2000 characters, without script/style)"]
B --> C["Prompt construction"]
C --> C1["system: SEO copywriter,<br>strict JSON"]
C --> C2["user: current tags + H1 +<br>text fragment + URL"]
C --> D["DeepSeek call (1 request)"]
D --> E["Parse JSON from response"]
E --> F["Output title / description / keywords<br>+ length validation"]
Step by step:
- Context collection (curl) — fetches the current
title,meta description,meta keywords,h1, and a text fragment (first 2000 characters, withoutscript/style). - Prompt construction — system role "SEO copywriter" with a strict JSON requirement, user part — collected context and URL.
- DeepSeek call — one request.
- Parse JSON from the response.
- Output title / description / keywords with length validation.
Key Detail: Forcing the Neural Network to Return Strict JSON
The problem with LLMs is they like to "decorate" the response with text. Therefore:
- The system prompt strictly specifies: "strictly in JSON format, without extra text".
temperature 0.4— minimal creativity.- On the PHP side, the response is parsed with the regex
\{[\s\S]*\}+json_decode, with a fallback to raw text if JSON parsing fails.
This ensures the frontend receives structured data, not "chatter."
// extract JSON block from the neural network response
preg_match('/\{[\s\S]*\}/', $raw, $m);
$meta = json_decode($m[0] ?? '', true);
if (!is_array($meta)) {
// fallback: response is not JSON — return raw text
$meta = ['raw' => $raw];
}
System prompt:
"You are an SEO copywriter. Generate meta tags strictly in JSON: title (up to 60), description (120–160 with CTA), keywords (5–7 words). No extra text."
Length Validation (Important UX Part)
The frontend calculates length and highlights the result:
title: ≤ 60 chars → green "optimal", otherwise red "⚠ too long"
description: 120–160 → green "optimal", yellow "⚠ too short/long"
keywords: 5–7 words → count check
So the tool doesn't just generate but also self-checks compliance with search engine requirements.
Protection Against API Budget Drain (Shared with AI Audit)
The tool shares the common protection engine with the AI audit:
- URL cache (
Cache.php, SQLite) — repeating the same URL doesn't hit the neural network. - Quota of 3 requests/day (
AiQuota.php) — shared across all AI features, key =user_id → cookie → IP. - SSRF protection — blocks internal addresses.
- DeepSeek key on the server — the frontend never sees it.
Verified: after three generations, the fourth request returns HTTP 429.
Real Result
Input: current title "Website creation and promotion Moscow: SEO promotion, GEO promotion…" (long, keyword-stuffed).
Neural network output:
| Tag | Result |
|---|---|
| title | "Website creation and promotion in Moscow — SEO, GEO" (up to 60 characters) |
| description | "We build selling websites and promote them in Moscow: SEO, GEO, contextual advertising. Increase the flow of leads and profit. Order…" (with CTA) |
| keywords | website creation, website promotion, SEO promotion, GEO promotion, SEO optimization, contextual advertising, Moscow |
The neural network itself "compressed" the long title to optimal length, added a call to action in the description, and collected relevant keywords.
Conclusions
- The value of an AI tool lies in the pipeline, not the LLM itself. Collected page context (title, description, H1, text fragment) forces the neural network to work for the specific page rather than produce a template.
- The LLM response format must be forcibly controlled. Strict system prompt "strictly in JSON" + regex + fallback to raw text protect the frontend from "chatter."
temperature 0.4is about predictability. The generator needs a stable structured result, not creativity.- Frontend self-check builds trust. Length highlighting (green/yellow/red) shows the user that meta tags meet search engine requirements.
- One protection engine for all AI features pays off. Cache, quota, and SSRF are not duplicated between the generator and the AI audit.
- Zero external libraries — pure PHP and vanilla JS with no backend dependencies.
