Quick Answer — Automating Grammar Fixes
Send user text to POST /api/v1/ai/grammar-fix and store data.result.corrected_text. Set return_explanations to true to get a list of every change with a reason, so you can auto-apply objective fixes such as spelling and punctuation and flag subjective ones such as tone. Call it from middleware, a model observer, a queued job or your own webhook handler.
Poorly written user input degrades content quality at scale: typos in product reviews, shouting in support tickets, inconsistent spelling in a knowledge base. This guide shows how to automate grammar and spelling fixes with the RSFlowHub Grammar Fix API: what the endpoint accepts and returns, the integration patterns that work (middleware, observers, queues and webhook receivers), how to keep code blocks safe, and how to decide which fixes to apply automatically.
RSFlowHub does not push webhooks to you. The “webhook” pattern here means your webhook endpoint (for example one called by your CMS or helpdesk when content changes) calling the Grammar Fix API and writing the corrected text back.
Validating user input at scale
Whether you run an online forum, a developer portal or an e-commerce review section, text quality affects trust and search visibility. Pages full of typos look careless to readers and give search engines a weaker signal about your content. Fixing text by hand does not scale, and rule-based spellcheckers cannot tell that "their" should be "there" or that a sentence is missing a verb.
An AI grammar endpoint reads the whole sentence in context, so it can correct spelling, grammar and punctuation in one pass, and, if you ask, adjust the tone. The key to using it well is not the API call itself but the policy around it: what you fix automatically, what you flag, and what you leave alone.
What the Grammar Fix API does
- Spelling, grammar and punctuation: corrects typos, tense errors, capitalisation and informal shorthand such as "bcuz".
- Tone control: the optional
tonefield rewrites toward a target such asprofessional,casualoracademic. The default,auto, keeps the original tone. - Dialect control: the optional
dialectfield (US,UK,AU) adjusts spellings such as color and colour. - Explanations: with
return_explanationsenabled, the response lists each change with the original text, the corrected text and a reason.
The endpoint corrects natural-language text. It is not a code linter or a markdown validator, and it does not check that brackets or code fences are balanced. If your content contains code, protect it before sending the text (see the section on code blocks below).
Making the request
Only text is required, with a maximum of 5,000 characters. This request asks for a professional tone and explanations:
curl -X POST "https://rsflowhub.com/api/v1/ai/grammar-fix" \
-H "X-API-Key: $RSFLOWHUB_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "I went to the store yesterday bcuz I need milk. the cashier was rude to me.",
"tone": "professional",
"dialect": "US",
"return_explanations": true
}'
{
"success": true,
"data": {
"result": {
"corrected_text": "I went to the store yesterday because I needed milk. The cashier was impolite to me.",
"changes_made": true,
"explanations": [
{ "original": "bcuz", "corrected": "because", "reason": "Corrected informal slang to standard spelling." },
{ "original": "need", "corrected": "needed", "reason": "Adjusted verb tense to match the past tense context of 'yesterday'." },
{ "original": "rude", "corrected": "impolite", "reason": "Adjusted vocabulary to sound more professional." }
]
}
}
}
Notice that the first two explanations are objective corrections and the third is a stylistic choice caused by the professional tone. That difference is exactly what your auto-apply policy needs.
Integration patterns: where to hook in
| Pattern | When it fires | Best for |
|---|---|---|
| Middleware (sync) | On request, before save | Short inputs where instant correction is worth about a second of delay |
| Model observer + queue | After save, in a background job | Laravel or Eloquent apps; no delay for the user |
| Webhook receiver | When your CMS or helpdesk reports a change | Cleaning content created outside your own app |
| Batch job | Scheduled, on a backlog | Cleaning existing content stores |
As a rule, avoid blocking the user's request with an AI call unless the correction is shown back to them (for example a "suggested fix" button). For everything that is stored silently, a queue is both faster and more resilient.
Laravel: observer plus queued job
The observer detects that the body changed and dispatches a job. The job calls the API and saves the corrected text, keeping the original for auditing:
public function handle(): void
{
$response = Http::withHeaders(['X-API-Key' => config('services.rsflowhub.key')])
->timeout(30)
->retry(2, 1000, throw: false)
->post('https://rsflowhub.com/api/v1/ai/grammar-fix', [
'text' => mb_substr($this->comment->body, 0, 5000),
'return_explanations' => true,
]);
if ($response->failed()) {
$this->release(120); // try again later; the original text stays published
return;
}
$result = $response->json('data.result');
if (! ($result['changes_made'] ?? false)) {
return;
}
$this->comment->update([
'original_body' => $this->comment->body,
'body' => $result['corrected_text'],
'grammar_changes' => $result['explanations'] ?? [],
]);
}
// In the observer:
// public function saved(Comment $comment): void
// {
// if ($comment->wasChanged('body') && ! $comment->wasChanged('original_body')) {
// FixGrammar::dispatch($comment);
// }
// }
Checking wasChanged('original_body') prevents an endless loop: the job's own update fires the observer again, but it will not queue a second run.
Webhook receiver in Node.js
If content is created in a headless CMS or helpdesk, point its "entry updated" webhook at an endpoint you control. The endpoint verifies the signature, acknowledges quickly, then fixes the text in the background:
import crypto from 'node:crypto';
import express from 'express';
const app = express();
app.post('/webhooks/cms', express.raw({ type: 'application/json' }), async (req, res) => {
// 1. Verify the sender (use the signing method your CMS documents).
const signature = req.get('x-signature') ?? '';
const expected = crypto.createHmac('sha256', process.env.CMS_WEBHOOK_SECRET)
.update(req.body).digest('hex');
const valid = signature.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
if (!valid) return res.sendStatus(401);
// 2. Acknowledge immediately; do the slow work afterwards.
res.sendStatus(202);
const { id, body } = JSON.parse(req.body).entry;
const fixed = await fixGrammar(body);
if (fixed && fixed.changes_made) await cms.updateEntry(id, { body: fixed.corrected_text });
});
async function fixGrammar(text) {
const res = await fetch('https://rsflowhub.com/api/v1/ai/grammar-fix', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-API-Key': process.env.RSFLOWHUB_KEY },
body: JSON.stringify({ text: text.slice(0, 5000), return_explanations: true }),
signal: AbortSignal.timeout(30_000),
});
return res.ok ? (await res.json()).data.result : null;
}
Be careful with webhook loops. When you write the corrected text back, the CMS will usually send another "entry updated" webhook. Skip entries that carry a marker you set (such as a grammar_checked flag), or compare the new text with the previous one before doing any work.
Keeping code blocks safe
Forum posts and documentation often mix prose with code. A grammar tool should never "correct" a variable name or reformat a snippet, so mask fenced code before sending the text and put it back afterwards:
export function protectCode(text) {
const blocks = [];
const masked = text.replace(/```[\s\S]*?```/g, (match) => {
blocks.push(match);
return `[[CODE_${blocks.length - 1}]]`;
});
return {
masked,
restore(fixed) {
// If a placeholder went missing, do not risk losing code: skip the fix.
const survived = blocks.every((_, i) => fixed.includes(`[[CODE_${i}]]`));
if (!survived) return null;
return fixed.replace(/\[\[CODE_(\d+)\]\]/g, (_, i) => blocks[Number(i)]);
},
};
}
// const { masked, restore } = protectCode(post.body);
// const fixed = await fixGrammar(masked);
// const finalText = fixed && restore(fixed.corrected_text);
The same idea works for inline code, URLs and product names you do not want touched: replace them with placeholders, fix the prose, then restore them.
The automatic cleanup pipeline
- Intercept: user text arrives through a form, import or webhook.
- Protect: mask code blocks, links and names that must not change.
- Fix: call the Grammar Fix API with
return_explanationsenabled. - Decide: apply spelling, grammar and punctuation changes automatically; send large or stylistic changes to review.
- Store: save the corrected text and keep the original and the explanations for an audit trail.
- Report: count changes per author or source to find who needs help, or where bad data comes from.
Apply objective fixes (spelling, punctuation, tense) automatically. Flag subjective ones: if a result changes more than a set share of the words, or the explanations mention tone or vocabulary, hold it for a human. Never silently rewrite what a user meant.
Common mistakes to avoid
- Overwriting the original. Always keep the user's version so a bad correction can be reverted.
- Forcing a tone on everyone. A
professionaltone is right for business messages and wrong for a casual forum. Use the defaultautounless you have a reason. - Sending code or markup. Mask it first; the endpoint is for natural language.
- Exceeding 5,000 characters. Split long articles by paragraph and fix each part separately.
- Blocking the request. Slow AI calls belong in queues unless the user sees the suggestion.
- Webhook loops. A write-back that triggers the same webhook will cycle forever unless you mark processed content.
Clean Every Submission Automatically
Wire the Grammar Fix API into your middleware, queue or webhook handler for spelling, grammar, tone and dialect fixes with a change-by-change explanation.
curl -X POST "https://rsflowhub.com/api/v1/ai/grammar-fix" \
-H "X-API-Key: YOUR_FLOWHUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "[user submission]", "return_explanations": true}'
Try Grammar Fix API →
Key Takeaways
- The Grammar Fix API returns
corrected_textand, withreturn_explanations, a reason for every change. - Auto-apply objective fixes (spelling, punctuation, tense); flag subjective ones (tone, vocabulary) for review.
- Prefer queues, observers and webhook receivers over blocking the user request.
- Mask code blocks, links and names before sending, and restore them afterwards.
- Keep the original text and the explanations for an audit trail.
- Limit: 5,000 characters per request; split longer content by paragraph.
Priya Sharma Member
3 days agoCustom debounced search hook in React TypeScript worked out of the box with zero re-render issues. 10/10!
Reply to Priya Sharma
Marcus Brody Member
3 days agoThe Laravel 11 service class extraction prompt is part of our standard pull request workflow now. Kept our controllers super thin!
Reply to Marcus Brody
David Kim Member
5 days agoOWASP security audit prompts caught an unindexed database query and potential SQL injection before our staging deploy. Lifesaver!
Reply to David Kim