ravinarayanan/Gemma4-E2b-SOQL-QLORA
Gemma 4 E2B — SOQL Query Generator (QLoRA, Q4KM GGUF)
Fine-tuned from [google/gemma-4-2b-it](https://huggingface.co/google/gemma-4-2b-it) to translate natural-language questions into SOQL (Salesforce Object Query Language) queries.
Note: The model is trained and prompted to return bare SOQL, but like all small LLMs it may occasionally include reasoning traces (<think>...</think>blocks), brief explanations, or off-script text. Always validate the output and strip non-SOQL content before execution. The reference orchestrator (orchestrator/app.py) handles this automatically.
Model details
What it does
Given a Salesforce object schema + a natural-language question, the model returns a SOQL SELECT query. It was trained on fictional object/field names (Vehicle__c, Driver__c, etc.) to learn SOQL syntax — not any specific org's schema. Inject your real org's schema in the user message at inference time.
SOQL patterns covered
Simple SELECT · WHERE filters · ORDER BY · LIMIT · COUNT/aggregate · GROUP BY · HAVING · date literals · multi-field · relationship queries · subquery IN filters · parent field traversal · child subqueries · LIKE · NULL checks · boolean logic · semi-joins
Usage with Ollama (recommended)
# Pull directly from this repo
ollama pull hf.co/ravinarayanan/gemma-2b-soql-qlora
# Or create from the bundled Modelfile
ollama create soql-gemma4 -f Modelfile
ollama run soql-gemma4Example prompt
Object: Vehicle__c
Fields: Name, Make__c, Model__c, Year__c, Price__c, FuelType__c, IsAvailable__c
Relationships: Dealership__c (lookup), ServiceRecords__r (child)
Write a SOQL query to find electric vehicles priced under 25000 that are availableExample output
The model typically returns bare SOQL, but may prefix it with a <think> block. Strip everything before and including </think> if present:
SELECT Name, Make__c, Model__c, Price__c
FROM Vehicle__c
WHERE FuelType__c = 'Electric'
AND Price__c < 25000
AND IsAvailable__c = trueParsing the output in Python
import re
def extract_soql(raw: str) -> str:
# Strip <think>...</think> block if present
raw = re.sub(r"<think>.*?</think>", "", raw, flags=re.DOTALL).strip()
# Take only the first SELECT statement
match = re.search(r"(SELECT\b.*)", raw, re.IGNORECASE | re.DOTALL)
return match.group(1).strip() if match else raw.strip()System prompt used at inference
You are a SOQL query generator. Given a Salesforce schema and a question,
output ONLY the bare SOQL query. No explanation, no markdown, no extra text,
no reasoning.Limitations
- Output not guaranteed to be pure SOQL — the model may include reasoning traces or brief text; validate and strip before execution
- Trained on synthetic data — always test generated queries against your org
- Only SELECT queries — DML (INSERT/UPDATE/DELETE) is intentionally excluded from training
- Schema must be provided in the user message; the model has no live Salesforce access
- 2B parameter model — complex nested subqueries may need a retry or prompt adjustment
Training data
11,040 synthetic training examples generated from a fictional Salesforce schema (4 objects: Vehicle__c, Driver__c, Dealership__c, ServiceRecord__c) covering 17 SOQL pattern types. Dataset was generated with a capability-aware template generator to ensure pattern diversity and avoid duplicates.
License
This model is derived from Gemma 4 and is subject to the Gemma Terms of Use.
