Gemma-3-4B-it-SQLi-Steered: a behavior-steered model for SQL injection detection
2 min readupdated
This model is based on google/gemma-3-4b-it (4.3B parameters) and features a built-in activation-steering vector that modifies the hidden state on the fly. Derived using the sparse autoencoder (SAE) mean feature difference method for the SQL injection concept, the vector is injected into the decoder output layer without altering the base weights. This shifts the model's focus toward vulnerability analysis and code logic without full fine-tuning. It is useful for developers and security researchers performing code audits and checking for vulnerabilities.
Key features
- The activation vector is applied at the 17th of 34 layers to steer generation.
- Base model weights remain unchanged, and the vector is stored in a separate
steering.safetensorsfile. - Easily disable or adjust intervention strength via configuration.
- Full support for standard
transformerslibrary classes.
What you can do
- Analyze source code snippets for SQL injection vulnerabilities.
- Compare the behavior of the steered model against the original base version to evaluate response changes.
- Conduct web application security audits with a focus on code execution paths.
Example
from transformers import AutoModelForImageTextToText, AutoProcessor
repo = "enriquetomasmb/gemma-3-4b-it-sqli-steered"
model = AutoModelForImageTextToText.from_pretrained(
repo, trust_remote_code=True, dtype="auto", device_map="auto"
)
processor = AutoProcessor.from_pretrained(repo)
messages = [{"role": "user", "content": [{"type": "text", "text": "Explain this code: ..."}]}]
inputs = processor.apply_chat_template(
messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt"
).to(model.device)
output = model.generate(**inputs)
print(processor.decode(output[0, inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
Read more
DetailsLayer: 17 of 34 (decoder output)
Intervention strength: 1.0 (adjustable)
Method: SAE mean feature difference (B - A)
Limitations: Requires the transformers library; not supported in vLLM, TGI, and llama.cpp










Comments