scieee AI-readable full text Open interactive document viewer

EGL: A Domain-Specific Language for Specifying and Enforcing Ethical Requirements in Large Language Models

Anonymous, Anonymous

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.

Full text

Inputs and Outputs EGL: A Domain-Specific Language for Specifying and Enforcing Ethical Requirements in Large Language Models Example 1 Policy Definition and Input: @debug policy my_policy(post): redact: email "*" end Input: Write to [email protected] Basic Output: Write to ********************** [DEBUG] redact: email (1) JSON Output: { "mode": "post", "status": "OK", "return_code": 0, "transformed_text": "Write to *********************", "actions_applied": [ {"action":"redact","evaluated":"email","count":1} ], "totals": {"forbid": 0, "redact": 1, "append": 0}, "debug": {"enabled": true} } 1 Example 2 Policy Definition and Input: @debug policy phone_block(pre): forbid: phone_number end Input: My phone is 5555-9213. Basic Output: FORBIDDEN OUTPUT [DEBUG] forbid: phone_number (1) JSON Output: { "mode": "pre", "status": "FORBIDDEN", "return_code": -2, "transformed_text": "My phone is 5555-9213.", "actions_applied": [ {"action":"forbid","evaluated":"phone_number","count":1} ], "totals": {"forbid": 1, "redact": 0, "append": 0}, "debug": {"enabled": true} } Example 3 Policy Definition and Input: @debug policy redact_email(post): append: email "There is an email on this message." end Input Please contact [email protected] for details. Basic Output Please contact [email protected] for details. There is an email on this message. [DEBUG] append: email (1) 2 Structured JSON Output { "mode": "post", "status": "OK", "return_code": 0, "transformed_text": "Please contact [email protected] for details. There is an email on this message.", "actions_applied": [ {"action":"append","evaluated":"email","count":1} ], "totals": {"forbid": 0, "redact": 0, "append": 1} } 3