Building a Domain-specific Guardrail Model in Production
Mohammad Niknazar, Paul V. Haley, Latha Ramanan, Sang T. Truong, Yedendra Shrinivasan, Ayan Kumar Bhowmick, Prasenjit Dey, Ashish Jagmohan, Hema Maheshwari, Shom Ponoth, Robert Smith, Aditya Vempaty, Nick Haber, Sanmi Koyejo, Sharad SundararajanarXiv2024 · DOI
Deploying Large Language Models (LLMs) in K-12 education requires balancing high-stakes safety requirements with strict production latency constraints. This paper presents SPADE (Safe and Performant AI Deployment with continuous Evaluation), a framework for building domain-specific guardrails. By fine-tuning mid-sized models and implementing output token optimizations, the authors demonstrate that a specialized Mistral 7B model can outperform general-purpose models like GPT-3.5 and Gemini Pro in toxicity detection while meeting sub-second latency targets on accessible hardware.
Introduction
While LLMs offer transformative potential for education, their deployment in K-12 environments necessitates rigorous safety filters that understand age-appropriateness and classroom context. General-purpose safety models often lack the nuance required for specific educational domains. Furthermore, production environments demand high reliability (FERPA/COPPA compliance), low latency (sub-second response), and cost-effectiveness.
The SPADE Framework
The authors propose the SPADE pipeline to bridge the gap between research performance and production requirements. The framework encompasses a full lifecycle from domain requirement definition to continuous evaluation.
The SPADE pipeline: from domain requirements to continuous evaluation.
Dataset Generation & Transformation: Utilizing a mix of proprietary classroom data (23,304 instances) and synthetic augmentation to ensure coverage of safe, controversial, and unsafe topics.
Model Optimization: Fine-tuning models (ranging from 2B to 13B parameters) using QLoRA. Mistral 7B was selected for its optimal performance-efficiency trade-off.
Output Token Compression: To minimize the "decode" bottleneck, the model is trained to output compressed strings (e.g., true A2B2C1...) instead of verbose JSON, significantly reducing inference time.
Experimental Results
The fine-tuned Mistral 7B model achieved an F1 score of 0.84 on internal benchmarks. When compared against state-of-the-art general models on public datasets, SPADE showed significant improvements in toxicity detection.
Comparative performance of SPADE ("Ours") against Gemini and GPT-3.5 across Civil Comments and Jigsaw Toxicity datasets.
On the Jigsaw Toxicity Prediction dataset, the SPADE model achieved an AUC ROC of 88.2, outperforming Gemini Pro's 82.5. In production settings on NVIDIA A100 GPUs, the system maintained a p50 latency of 570ms for batch sizes of 8, proving its viability for real-time classroom applications.
Conclusion
SPADE demonstrates that domain-specific fine-tuning and targeted architectural optimizations allow smaller models to surpass larger, general-purpose LLMs in specialized safety tasks. Future work will focus on pedagogical alignment—ensuring the model supports the learning process rather than just providing answers—and expanding the framework to handle multimodal inputs common in modern digital classrooms.
Summary updated
Abstract
Generative AI holds the promise of enabling a range of sought-after capabilities and revolutionizing workflows in various consumer and enterprise verticals. However, putting a model in production involves much more than just generating an output. It involves ensuring the model is reliable, safe, performant and also adheres to the policy of operation in a particular domain. Guardrails as a necessity for models has evolved around the need to enforce appropriate behavior of models, especially when they are in production. In this paper, we use education as a use case, given its stringent requirements of the appropriateness of content in the domain, to demonstrate how a guardrail model can be trained and deployed in production. Specifically, we describe our experience in building a production-grade guardrail model for a K-12 educational platform. We begin by formulating the requirements for deployment to this sensitive domain. We then describe the training and benchmarking of our domain-specific guardrail model, which outperforms competing open- and closed- instruction-tuned models of similar and larger size, on proprietary education-related benchmarks and public benchmarks related to general aspects of safety. Finally, we detail the choices we made on architecture and the optimizations for deploying this service in production; these range across the stack from the hardware infrastructure to the serving layer to language model inference optimizations. We hope this paper will be instructive to other practitioners looking to create production-grade domain-specific services based on generative AI and large language models.
@misc{niknazar2024building,
author = {Mohammad Niknazar and Paul V. Haley and Latha Ramanan and Sang T. Truong and Yedendra Shrinivasan and Ayan Kumar Bhowmick and Prasenjit Dey and Ashish Jagmohan and Hema Maheshwari and Shom Ponoth and Robert Smith and Aditya Vempaty and Nick Haber and Sanmi Koyejo and Sharad Sundararajan},
title = {{Building a Domain-specific Guardrail Model in Production}},
year = {2024},
eprint = {2408.01452},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2408.01452},
}