pawlaszc/DigitalForensicsText2SQLite
ForensicSQL-Llama-3.2-3B
Model Description
ForSQLiteLM (ForensicSQL-Llama-3.2-3B) is a fine-tuned Llama 3.2-3B model specialized for generating SQLite queries from natural language requests against mobile forensic databases. The model converts investigative questions into executable SQL queries across a wide range of forensic artefact databases — WhatsApp, Signal, iMessage, Android SMS, iOS Health, WeChat, Instagram, blockchain wallets, and many more.
This model was developed as part of a research project and accompanying journal paper investigating LLM fine-tuning for forensic database analysis, and is integrated into FQLite, an established open-source forensic analysis tool.
Key result: 93.0% execution accuracy on a 100-example held-out test set — within 4 percentage points of GPT-4o (95.0%) evaluated under identical conditions (McNemar test: p ≈ 0.39, not significant at α = 0.05), while running fully locally with no internet connectivity required.
Model Details
Performance
Overall Results (fixed dataset, n=100, best configuration)
Accuracy by Query Difficulty
ForSQLiteLM matches GPT-4o exactly on Easy and Medium queries. The remaining gap is concentrated on Hard queries (complex CTEs, window functions, multi-table joins).
Accuracy by Forensic Domain
Prompt Configuration Ablation
★ Primary configuration — omitting the application name from the prompt yields 3 pp higher overall accuracy. Interestingly, including the app name helps iOS CoreData schemas (+4 pp) but hurts Hard queries (−7.4 pp); the primary configuration without app name is recommended for general use.
Post-Processing Pipeline Contribution
Training Progression
Intended Use
Primary Use Cases
- Mobile forensics investigations: automated SQL query drafting against seized device databases
- Integration into forensic tools (FQLite, Autopsy, ALEAPP/iLEAPP workflows)
- Research in domain-specific Text-to-SQL
- Educational use for learning forensic database analysis
Important: This Model is a Drafting Assistant
ForSQLiteLM is not a replacement for SQL expertise. It generates candidate queries that require review by a practitioner with sufficient SQL knowledge before any reliance is placed on their results. The 93.0% accuracy means approximately 1 in 14 queries contains an error. In court-admissible or case-critical work, all outputs must be independently validated.
Out-of-Scope Use
- Autonomous forensic decision-making without human review
- General-purpose SQL generation outside the forensic domain
- Non-SQLite databases (PostgreSQL, MySQL, etc.)
How to Use
Quick Start (Transformers)
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_name = "pawlaszc/ForensicSQL-Llama-3.2-3B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto"
)
model.eval()
schema = """
CREATE TABLE message (
ROWID INTEGER PRIMARY KEY,
text TEXT,
handle_id INTEGER,
date INTEGER,
is_from_me INTEGER,
cache_has_attachments INTEGER
);
CREATE TABLE handle (
ROWID INTEGER PRIMARY KEY,
id TEXT,
service TEXT
);
"""
request = "Find all messages received in the last 7 days that contain attachments"
# Note: do NOT use apply_chat_template — use plain-text prompt
prompt = f"""Generate a valid SQLite query for this forensic database request.
Database Schema:
{schema}
Request: {request}
SQLite Query:
"""
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=2048)
inputs = {k: v.to(model.device) for k, v in inputs.items()}
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=300,
do_sample=False, # greedy decoding — do not change
)
input_length = inputs['input_ids'].shape[1]
sql = tokenizer.decode(outputs[0][input_length:], skip_special_tokens=True)
print(sql.strip())Important: Use plain-text tokenization (do not callapply_chat_template). The model was trained and evaluated with a plain-text prompt format. Usedo_sample=False(greedy decoding) for reproducible results.
Python Helper Class
class ForensicSQLGenerator:
def __init__(self, model_name="pawlaszc/ForensicSQL-Llama-3.2-3B"):
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
self.model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto"
)
self.model.eval()
def generate_sql(self, schema: str, request: str) -> str:
prompt = (
"Generate a valid SQLite query for this forensic database request.\n\n"
f"Database Schema:\n{schema}\n\n"
f"Request: {request}\n\n"
"SQLite Query:\n"
)
inputs = self.tokenizer(
prompt, return_tensors="pt", truncation=True, max_length=4096
)
inputs = {k: v.to(self.model.device) for k, v in inputs.items()}
input_length = inputs["input_ids"].shape[1]
with torch.no_grad():
outputs = self.model.generate(
**inputs, max_new_tokens=300, do_sample=False
)
sql = self.tokenizer.decode(
outputs[0][input_length:], skip_special_tokens=True
)
# Return first statement only, normalized
return sql.strip().split("\n")[0].strip().rstrip(";") + ";"
# Usage
generator = ForensicSQLGenerator()
sql = generator.generate_sql(schema, "Find all unread messages from the last 24 hours")
print(sql)With Ollama / llama.cpp (GGUF)
# With llama.cpp
./llama-cli -m forensic-sql-q4_k_m.gguf \
--temp 0 \
-p "Generate a valid SQLite query for this forensic database request.
Database Schema:
CREATE TABLE sms (_id INTEGER PRIMARY KEY, address TEXT, body TEXT, date INTEGER);
Request: Find all messages sent after midnight
SQLite Query:"
# With Ollama — create a Modelfile
cat > Modelfile << 'EOF'
FROM ./forensic-sql-q4_k_m.gguf
PARAMETER temperature 0
PARAMETER num_predict 300
EOF
ollama create forensic-sql -f Modelfile
ollama run forensic-sqlTraining Details
Dataset — SQLiteDS
- Total examples: 1,000 (800 train / 100 val / 100 test), fixed random seed 42
- Forensic artifact categories: 191
- Reference query validation: All 1,000 reference queries validated for execution correctness against in-memory SQLite; 50 queries (5%) corrected before final training
- Augmentation: 3.4× expansion via instruction paraphrasing, WHERE clause reordering, and LIMIT injection — augmented examples confined to training split only
- Dataset: pawlaszc/mobile-forensics-sql
- License: CC BY 4.0
Hyperparameters
Limitations
Known Issues
- iOS CoreData Schemas (92.0%): The Z-prefix column naming convention (e.g.,
ZISFROMME,ZTIMESTAMP) provides no semantic signal from column names alone, making these schemas harder to reason about. - Hard Queries — 3.7 pp gap to GPT-4o: Complex CTEs, recursive queries, and window functions are the primary remaining challenge.
- Finance & Crypto (81.8%, n=11): Small test set; confidence intervals are wide. Interpret with caution.
- ~1 in 11 error rate: Approximately 9% of generated queries will contain errors. Expert review of all outputs is required before use in investigations.
When Human Review is Especially Important
- Complex multi-table queries with CTEs or window functions
- Case-critical or court-admissible investigations
- Any query that will be used to draw conclusions about a suspect
- Queries involving rare or unusual forensic artifact schemas
Evaluation
- Test set: 100 examples, held-out, seed=42, non-augmented
- Metric: Execution accuracy — query is correct iff it executes without error AND returns a result set identical to the reference query
- Reference validation: All reference queries validated for execution correctness before evaluation; 5 broken queries in the test set were corrected
- Evaluation script: Available in the dataset repository on Zenodo ([DOI])
Citation
If you use this model or the SQLiteDS dataset in your research, please cite:
@article{pawlaszczyk2026forsqlitelm,
author = {Dirk Pawlaszczyk},
title = {AI-Based Automated SQL Query Generation for SQLite Databases
in Mobile Forensics},
journal = {Forensic Science International: Digital Investigation},
year = {2026},
note = {FSIDI-D-26-00029}
}License
Apache 2.0 — following the base Llama 3.2 license terms.
Acknowledgments
- Base model: Meta's Llama 3.2-3B-Instruct
- Training framework: Hugging Face Transformers
- Forensic tool integration: FQLite
- Schema sources: iLEAPP, ALEAPP, Autopsy (used under their respective open-source licenses)
Additional Resources
- Dataset (Zenodo): [SQLiteDS — DOI to be added on publication]
- Dataset (HuggingFace): pawlaszc/mobile-forensics-sql
- FQLite integration: github.com/pawlaszczyk/fqlite
- Paper: FSIDI-D-26-00029 (under review)
Disclaimer: ForSQLiteLM is intended for research and forensic practitioner use. All generated SQL queries must be reviewed by a qualified practitioner before execution in live forensic investigations. The authors accept no liability for incorrect conclusions drawn from unvalidated model outputs.
