EGL: A Domain-Specific Language for Specifying and Enforcing Ethical Requirements in Large Language Models
Abstract
Context and motivation: Although large language models (LLMs) are increasingly influential in decision-making, most ethical AI efforts remain descriptive, offering principles without mechanisms for enforcement. This work explores how ethical constraints can be expressed and enforced at inference time. Question/problem: This work investigates how abstract ethical principles, such as privacy and non-maleficence, can be translated into verifiable runtime policies. Specifically, we explore whether a domain-specific language (DSL) can reliably encode these principles while remaining both interpretable and adaptable. Principal ideas and results: We present EGL v0.1 (Ethics Guard Language), a domain-specific language (DSL) that compiles ethical specifications into modular runtime handlers for LLM inference. EGL also introduces pragmas, such as "@debug" and "@aggressive", allowing developers to tune diagnostic output and detection sensitivity. An empirical evaluation of 346 labeled examples showed high precision and recall for structured categories, such as "IP" and "phone", while also highlighting challenges related to the subjective category of "self-harm encouragement". Furthermore, the evaluation demonstrated that by enabling "@aggressive" resulted in increased recall from 0.56 to 0.89, which demonstrates pragma-driven adaptability. Contribution: EGL v0.1 provides an proof-of-concept practical solution for enforcing ethical safeguards in LLM inference, bridging the gap between normative principles and technical control. Although it is effective in interpreting explicit cues, it is limited in its ability to interpret contextual or nuanced moral intent, which will require future semantic and context-aware extensions.