Home
TR

AI rule generator

Generate regex from natural language with your own Gemini API key — stored on device, opt-in.

Validation rules are built on regex (regular expressions), and writing regex is not everyone’s strength. The AI rule generator lets you skip that step: you describe what you want to capture in plain language (“a six-digit serial number”, “an IBAN that starts with TR”, “a year-month-day date”), and QCR Scanner proposes a matching regex pattern for you. The feature is entirely optional, uses your own API key, and only runs when you ask it to.

How it works

The feature uses Google’s Gemini 2.0 Flash model. The plain-language prompt you type is sent to the model, and the model returns a corresponding regex pattern. You can drop that pattern straight into a validation rule, fine-tune it by hand if needed, and start using it while scanning.

The key point: the scanning engine itself (OCR and QR) never uses the network — this feature runs only to generate the rule text, that is, when you tap “generate rule”. The images, frames, or list values you scan are never sent here. Only the prompt text you type goes out.

Getting your own API key

This feature requires your own Gemini API key. The key is available for free from Google AI Studio:

  1. Open Google AI Studio in a browser and sign in with your Google account.
  2. Create a new key under Get API key.
  3. Copy the generated key.
  4. Paste it into the AI rule generator field in QCR Scanner.

Once you enter the key, it is stored on the device, so you do not have to re-enter it each time. The key stays only on your device; it is not sent to ReviseTouch servers or anywhere else.

Note: Your API key is like a password — do not share it with anyone. To revoke or rotate it, delete the old key in Google AI Studio, create a new one, and update it in the app.

Generating a rule

  1. Open the AI generation field on the validation rules screen.
  2. Describe the value you want to capture in plain language. Examples:
    • “Exactly a 6-digit number”
    • “An IBAN that starts with TR and is 24 characters long”
    • “A product code in the form uppercase letter, dash, four digits”
  3. Tap the generate button. The request goes to Gemini with the x-goog-api-key header and a regex pattern comes back.
  4. Review the suggested pattern. Edit it by hand if needed.
  5. Save the pattern as a validation rule. A rule name can be at most 12 characters.

A generated pattern behaves like any ordinary validation rule: ReDoS protection (overly long or dangerous patterns are rejected) applies to these rules too, and only values matching all enabled rules are added to the list. See the validation rules page for details.

Tip: The regex the AI produces is a starting point, not a final verdict. Try the generated pattern against a few real samples; if it comes out too narrow or too broad, write your request more specifically and regenerate, or adjust the pattern by hand.

Technical detail

The request is sent to this endpoint:

POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent

Authentication is done with your own API key carried in the x-goog-api-key HTTP header, not in the request body. The body contains only the prompt text you typed; no scanned image, camera frame, or list content is sent.

Property Detail
Model Gemini 2.0 Flash
Endpoint generativelanguage.googleapis.com/v1beta/...
Authentication x-goog-api-key header (your own key)
What is sent Prompt text only (not the image)
Key location Stored on device
When it runs Only when you tap “generate rule”

Privacy note

This is one of the few components in QCR Scanner that uses the network, so it is worth being clear about exactly what happens:

  • OCR and QR scanning use no network. The recognition engine is Google ML Kit and runs entirely on the device.
  • AI rule generation is opt-in. It runs only when you enter an API key and choose to generate a rule.
  • Only your prompt text goes out. Your images and list values are not sent to Gemini.
  • The key stays on the device. ReviseTouch never sees or stores your API key.

The request sent to Gemini is subject to Google’s API terms. For the overall privacy approach, see the privacy page.

Next steps

  • Validation rules — regex-based accept/reject and ReDoS protection
  • Smart Extract — pull rule-matching parts out of noisy text automatically
  • Scanning — the viewfinder, capture modes, and the OCR + QR flow
  • Privacy — what stays on the device and what uses the network

Made by ReviseTouch.