
LLM 채팅 앱을 위한 프로그래밍 가능한 가드레일: 입력/출력 레일을 적용하고, 탈옥(jailbreak)과 프롬프트 인젝션을 차단하며, 환각을 감지하고, 민감한 데이터를 마스킹합니다.
최신 릴리스 / 개발 버전: develop 브랜치는 최신 개발 트리 상태를 추적합니다. 최신 릴리스 버전은 0.23.0입니다.
✨✨✨
📌 공식 NeMo Guardrails 라이브러리 문서는 docs.nvidia.com/nemo/guardrails에서 확인할 수 있습니다.
✨✨✨
NVIDIA NeMo Guardrails 라이브러리는 LLM 기반 대화형 애플리케이션에 *프로그래밍 가능한 가드레일(guardrails)*을 쉽게 추가할 수 있게 해주는 오픈소스 툴킷입니다. 가드레일(줄여서 "rails")은 대규모 언어 모델의 출력을 제어하는 특정 방식으로, 예를 들어 정치에 대해 이야기하지 않기, 특정 사용자 요청에 특정한 방식으로 응답하기, 미리 정의된 대화 경로 따르기, 특정 언어 스타일 사용하기, 구조화된 데이터 추출하기 등이 있습니다.
이 논문은 NeMo Guardrails 라이브러리를 소개하며 시스템과 현재 평가에 대한 기술적 개요를 제공합니다.
Python 3.10, 3.11, 3.12 또는 3.13.
pip로 설치하려면:```bash
pip install nemoguardrails
자세한 지침은 [설치 가이드](https://docs.nvidia.com/nemo/guardrails/get-started/installation-guide)를 참조하세요.
## 개요
<!-- start-documentation-reuse -->
NeMo Guardrails 라이브러리는 LLM 기반 애플리케이션을 개발하는 개발자가 애플리케이션 코드와 LLM 사이에 **프로그래밍 가능한 가드레일(programmable guardrails)**을 추가할 수 있게 해줍니다.
<div align="center">
<img src="https://raw.githubusercontent.com/NVIDIA-NeMo/Guardrails/develop/docs/_static/images/programmable_guardrails.png" width="75%" alt="Programmable Guardrails">
</div>
*프로그래밍 가능한 가드레일*을 추가함으로써 얻을 수 있는 주요 이점은 다음과 같습니다:
- **신뢰할 수 있고 안전하며 보안성이 높은 LLM 기반 애플리케이션 구축:** 대화를 안내하고 보호하는 레일을 정의할 수 있습니다. 특정 주제에 대한 LLM 기반 애플리케이션의 동작을 정의하고 원치 않는 주제에 대한 논의를 방지하도록 선택할 수 있습니다.
- **모델, 체인 및 기타 서비스를 안전하게 연결:** LLM을 다른 서비스(일명 도구)에 원활하고 안전하게 연결할 수 있습니다.
- **제어 가능한 대화:** LLM이 사전 정의된 대화 경로를 따르도록 유도하여 대화 설계 모범 사례에 따라 상호작용을 설계하고 표준 운영 절차(예: 인증, 지원)를 적용할 수 있습니다.
<!-- end-documentation-reuse -->
### LLM 취약점으로부터 보호
NeMo Guardrails 라이브러리는 LLM 기반 채팅 애플리케이션을 탈옥(jailbreak) 및 프롬프트 인젝션과 같은 일반적인 LLM 취약점으로부터 보호하는 여러 메커니즘을 제공합니다. 아래는 이 저장소에 포함된 예제 [ABC Bot](https://github.com/nvidia-nemo/guardrails/blob/develop/examples/bots/abc)에 대한 다양한 가드레일 구성이 제공하는 보호 기능의 샘플 개요입니다. 자세한 내용은 [LLM 취약점 스캐닝](https://docs.nvidia.com/nemo/guardrails/evaluation/llm-vulnerability-scanning.html) 페이지를 참조하세요.
<div align="center">
<img src="https://raw.githubusercontent.com/NVIDIA-NeMo/Guardrails/develop/docs/_static/images/abc-llm-vulnerability-scan-results.png" width="500">
</div>
### 사용 사례
프로그래밍 가능한 가드레일은 다양한 유형의 사용 사례에서 사용할 수 있습니다:
1. **문서 집합에 대한 질의응답**(일명 검색 증강 생성): 사실 확인과 출력 검열을 적용합니다.
2. **도메인 특화 어시스턴트**(일명 챗봇): 어시스턴트가 주제를 벗어나지 않고 설계된 대화 흐름을 따르도록 보장합니다.
3. **LLM 엔드포인트**: 더 안전한 고객 상호작용을 위해 맞춤형 LLM에 가드레일을 추가합니다.
4. **LangChain 체인**(선택 사항): 어떤 사용 사례에서든 LangChain을 사용한다면 체인 주변에 가드레일 계층을 추가할 수 있습니다. 이 통합을 활성화하려면 `NEMOGUARDRAILS_LLM_FRAMEWORK=langchain` 환경 변수를 설정하거나 `set_default_framework("langchain")`을 호출하세요.
### 사용 방법
애플리케이션에 프로그래밍 가능한 가드레일을 추가하려면 Python API 또는 가드레일 서버를 사용할 수 있습니다(자세한 내용은 [서버 가이드](https://docs.nvidia.com/nemo/guardrails/get-started/integrate-into-application) 참조). Python API를 사용하는 것은 LLM을 직접 사용하는 것과 유사합니다. LLM 대신 가드레일 계층을 호출하는 것은 코드 베이스에 최소한의 변경만 필요하며, 두 가지 간단한 단계로 이루어집니다:
1. 가드레일 구성을 로드하고 `LLMRails` 인스턴스를 생성합니다.
2. `generate`/`generate_async` 메서드를 사용하여 LLM을 호출합니다.```python
from nemoguardrails import LLMRails, RailsConfig
# Load a guardrails configuration from the specified path.
config = RailsConfig.from_path("PATH/TO/CONFIG")
rails = LLMRails(config)
completion = rails.generate(
messages=[{"role": "user", "content": "Hello world!"}]
)
I notice that the input content for chunk 5 of 32 is missing — the "INPUT:" section is empty. There is no Markdown content provided to translate.
Please provide the actual chunk content, and I will translate it into Korean following all the specified rules.```json {"role": "assistant", "content": "Hi! How can I help you?"}
The input and output format for the `generate` method is similar to the [Chat Completions API](https://platform.openai.com/docs/guides/gpt/chat-completions-api) from OpenAI.
#### Async API
The NeMo Guardrails library is an async-first toolkit as the core mechanics are implemented using the Python async model. The public methods have both a sync and an async version. For example: `LLMRails.generate` and `LLMRails.generate_async`.
### Supported LLMs
You can use NeMo Guardrails with multiple LLMs like OpenAI GPT-3.5, GPT-4, LLaMa-2, Falcon, Vicuna, or Mosaic. For more details, check out the [Supported LLM Models](https://docs.nvidia.com/nemo/guardrails/about-nemo-guardrails-library/supported-llms) section in the Configuration Guide.
### Types of Guardrails
The NeMo Guardrails library supports five main types of guardrails:
<div align="center">
<img src="https://raw.githubusercontent.com/NVIDIA-NeMo/Guardrails/develop/docs/_static/images/programmable_guardrails_flow.png" width="75%" alt="Programmable Guardrails Flow">
</div>
1. **Input rails**: applied to the input from the user; an input rail can reject the input, stopping any additional processing, or alter the input (e.g., to mask potentially sensitive data, to rephrase).
2. **Dialog rails**: influence how the LLM is prompted; dialog rails operate on canonical form messages for details see [Colang Guide](https://docs.nvidia.com/nemo/guardrails/configure-guardrails/colang)) and determine if an action should be executed, if the LLM should be invoked to generate the next step or a response, if a predefined response should be used instead, etc.
3. **Retrieval rails**: applied to the retrieved chunks in the case of a RAG (Retrieval Augmented Generation) scenario; a retrieval rail can reject a chunk, preventing it from being used to prompt the LLM, or alter the relevant chunks (e.g., to mask potentially sensitive data).
4. **Execution rails**: applied to input/output of the custom actions (a.k.a. tools), that need to be called by the LLM.
5. **Output rails**: applied to the output generated by the LLM; an output rail can reject the output, preventing it from being returned to the user, or alter it (e.g., removing sensitive data).
### Guardrails Configuration
A guardrails configuration defines the **LLM(s)** to be used and **one or more guardrails**. A guardrails configuration can include any number of input/dialog/output/retrieval/execution rails. A configuration without any configured rails will essentially forward the requests to the LLM.
The standard structure for a guardrails configuration folder looks like this:```
.
├── config
│ ├── actions.py
│ ├── config.py
│ ├── config.yml
│ ├── rails.co
│ ├── ...
config.yml에는 LLM 모델, 활성 rails, 사용자 지정 구성 데이터와 같은 모든 일반 구성 옵션이 포함되어 있습니다". config.py 파일에는 사용자 지정 초기화 코드가 포함되어 있으며, actions.py에는 사용자 지정 Python 액션이 포함되어 있습니다. 전체 개요는 Configuration Guide를 참조하세요.
다음은 config.yml 예시입니다:```yaml
models:
rails:
input: flows: - check jailbreak - mask sensitive data on input
output: flows: - self check facts - self check hallucination - activefence moderation on input
config: # Configure the types of entities that should be masked on user input. sensitive_data_detection: input: entities: - PERSON - EMAIL_ADDRESS
guardrails 구성에 포함된 `.co` 파일에는 다양한 유형의 rails를 정의하는 Colang 정의(Colang이 무엇인지에 대한 간략한 개요는 다음 섹션을 참조하세요)가 포함되어 있습니다. 아래는 사용자에게 인사하는 dialog rails를 정의하는 `greeting.co` 파일의 예입니다.```colang
define user express greeting
"Hello!"
"Good afternoon!"
define flow
user express greeting
bot express greeting
bot offer to help
define bot express greeting
"Hello there!"
define bot offer to help
"How can I help you today?"
다음은 모욕에 대한 대화 레일(dialog rail)을 위한 Colang 정의의 추가 예시입니다:```colang define user express insult "You are stupid"
define flow user express insult bot express calmly willingness to help
### Colang
다양한 유형의 가드레일을 구성하고 구현하기 위해, 이 툴킷은 **Colang**을 도입합니다. Colang은 유연하면서도 제어 가능한 대화 흐름을 설계하기 위해 특별히 만들어진 모델링 언어입니다. Colang은 파이썬과 유사한 문법을 가지며, 특히 개발자에게 간단하고 직관적이도록 설계되었습니다.```{note}
Two versions of Colang, 1.0 and 2.0, are supported and Colang 1.0 is the default.
Colang 1.0 구문에 대한 간략한 소개는 Colang 1.0 언어 구문 가이드를 참조하세요.
Colang 2.0을 시작하려면 Colang 2.0 문서를 참조하세요.
NeMo Guardrails에는 일련의 내장 guardrails가 함께 제공됩니다.```{note} The built-in guardrails may or may not be suitable for a given production use case. As always, developers should work with their internal application team to ensure guardrails meets requirements for the relevant industry and use case and address unforeseen product misuse.
라이브러리에는 LLM 자체 점검(입력/출력 모더레이션, 사실 확인, 환각 탐지)을 위한 가드레일, NVIDIA 안전 모델(콘텐츠 안전, 주제 안전), 탈옥 및 주입 탐지, 커뮤니티 모델 및 타사 API와의 통합이 포함됩니다. 전체 목록은 [Guardrails Library 문서](https://docs.nvidia.com/nemo/guardrails/user-guides/guardrails-library.html)를 참조하세요.
## CLI
NeMo Guardrails 라이브러리에는 내장 CLI도 함께 제공됩니다.```bash
$ nemoguardrails --help
Usage: nemoguardrails [OPTIONS] COMMAND [ARGS]...
actions-server Start a NeMo Guardrails actions server.
chat Start an interactive chat session.
evaluate Run an evaluation task.
server Start a NeMo Guardrails server.
NeMo Guardrails 라이브러리 CLI를 사용하여 guardrails 서버를 시작할 수 있습니다. 서버는 지정된 폴더에서 하나 이상의 구성을 로드하고 이를 사용하기 위한 HTTP API를 노출할 수 있습니다.``` nemoguardrails server [--config PATH/TO/CONFIGS] [--port PORT]
예를 들어, `sample` config에 대한 chat completion을 가져오려면 `/v1/chat/completions` 엔드포인트를 사용할 수 있습니다:```
POST /v1/chat/completions
입력이 비어 있습니다. 번역할 콘텐츠가 제공되지 않았습니다.```json { "config_id": "sample", "messages": [{ "role":"user", "content":"Hello! What can you do for me?" }] }
샘플 출력:```json
{"role": "assistant", "content": "Hi! How can I help you?"}
가드레일 서버를 시작하려면 Docker 컨테이너를 사용할 수도 있습니다. NeMo Guardrails 라이브러리는 nemoguardrails 이미지를 빌드하는 데 사용할 수 있는 Dockerfile을 제공합니다. 자세한 내용은 Docker 사용 섹션을 참조하세요.
LangChain 통합은 옵트인 방식입니다. 활성화하려면 NEMOGUARDRAILS_LLM_FRAMEWORK=langchain 환경 변수를 설정하거나 set_default_framework("langchain")을 호출하세요. 그런 다음 구성에 필요한 LangChain 패키지를 설치하세요. 통합을 활성화한 후에는 LangChain 체인(또는 모든 Runnable)을 가드레일 구성으로 감쌀 수 있으며, 가드레일 구성 내에서 LangChain 체인을 호출할 수도 있습니다. 자세한 내용은 LangChain 통합 문서를 참조하세요.
LLM 기반 대화형 애플리케이션의 안전성을 평가하는 것은 복잡한 작업이며 여전히 열린 연구 질문입니다. 적절한 평가를 지원하기 위해 NeMo Guardrails 라이브러리는 다음을 제공합니다:
nemoguardrails evaluate.LLM 기반 대화형 애플리케이션에 가드레일을 추가하는 방법은 다양합니다. 예를 들어: 명시적 중재 엔드포인트(예: OpenAI, ActiveFence, PolicyAI), 비판 체인(예: constitutional chain), 출력 파싱(예: guardrails.ai), 개별 가드레일(예: LLM-Guard), RAG 애플리케이션용 환각 탐지(예: Got It AI, Patronus Lynx).
NeMo Guardrails 라이브러리는 이러한 모든 보완적 접근 방식을 하나의 응집력 있는 LLM 가드레일 계층으로 통합할 수 있는 유연한 툴킷을 제공하는 것을 목표로 합니다. 예를 들어, 이 툴킷은 ActiveFence, PolicyAI, AlignScore 및 LangChain 체인과의 즉시 사용 가능한 통합을 제공합니다.
우리가 아는 한, NeMo Guardrails 라이브러리는 사용자와 LLM 간의 대화를 모델링하는 솔루션도 제공하는 유일한 가드레일 툴킷입니다. 이를 통해 한편으로는 대화를 정밀하게 안내할 수 있습니다. 다른 한편으로는 특정 가드레일을 사용해야 하는 시기를 세밀하게 제어할 수 있습니다. 예를 들어 특정 유형의 질문에만 사실 확인을 사용하는 경우입니다.
NVIDIA NeMo Guardrails 라이브러리는 NVIDIA가 어떤 배포 패턴과 안전 기능이 가장 많이 사용되는지 이해할 수 있도록 익명 원격 측정을 수집합니다. 이 라이브러리는 LLMRails, IORails 또는 Guardrails를 인스턴스화할 때 사용 이벤트 하나를 발송한 다음 프로세스당 단일 데몬 스레드에서 주기적으로 하트비트를 발송합니다. 이 원격 측정은 요청별 추적과는 별개입니다. 추적은 가드레일 구성에서 설정하고 자체 관측 백엔드로 보냅니다. 원격 측정은 NVIDIA로 전송되는 최소한의 익명 핑입니다.
2026년 5월 22일–8월 18일 동안의 정확한 0.22.0 및 0.23.0 릴리스 빌드에 걸친 익명 사용 현황 집계:



마지막 업데이트: 2026년 8월 18일
원격 측정에는 다음이 포함됩니다:
openai, nim, nvidia_ai_endpoints) - 모델 이름이나 자격 증명은 절대 포함되지 않습니다.jailbreak_detection, content_safety, topic_safety)library, api 또는 cli 서버)LLMRails 또는 IORails)이벤트 페이로드에는 사용자 콘텐츠가 수집되지 않습니다. 페이로드에는 모델 이름, API 키, 엔드포인트, 프롬프트, 완성 결과, 토큰 수, 요청별 메트릭, 파일 경로, 사용자 이름 또는 IP 주소가 포함되지 않습니다. NVIDIA는 데이터를 집계하여 엔지니어링 작업의 우선순위를 정하는 데 사용하며, 채택 동향을 커뮤니티와 공유할 것입니다.
또한 라이브러리는 각 이벤트 페이로드를 ~/.config/nemoguardrails/usage_stats.json의 로컬 감사 파일에 쓰려고 시도합니다. 감사 파일에는 전체 NVIDIA 원격 측정 봉투가 아닌 이벤트 JSONL이 저장됩니다. 감사 쓰기는 최선형(best effort)이며, 로컬 감사 쓰기가 실패해도 원격 측정 전송은 계속 진행됩니다.
원격 측정을 비활성화하려면 다음 옵션 중 하나를 설정하세요.```bash export NEMO_GUARDRAILS_NO_USAGE_STATS=1
export DO_NOT_TRACK=1
mkdir -p ~/.config/nemoguardrails && touch ~/.config/nemoguardrails/do_not_track
NVIDIA NeMo Guardrails 라이브러리가 시작되기 전에 옵트아웃을 설정하세요. 텔레메트리가 시작된 후 환경 변수를 변경하거나 `do_not_track`을 생성해도 이미 실행 중인 하트비트 스레드는 중지되지 않습니다.
전체 스키마와 필드별 설명은 [docs/telemetry.md](https://docs.nvidia.com/nemo/guardrails/latest/telemetry.html)를 참조하세요.
언제든지 텔레메트리 수집을 옵트아웃할 수 있습니다. 옵트아웃은 NVIDIA NeMo Guardrails 라이브러리 자체의 데이터 수집에만 적용됩니다.
타사 엔드포인트에는 별도의 이용 약관과 개인정보 처리 방침이 적용됩니다. NVIDIA NeMo Guardrails 라이브러리는 NVIDIA Build(`build.nvidia.com`)와 같은 추론 엔드포인트를 사용할 수 있습니다. NVIDIA Build 또는 다른 타사 엔드포인트를 사용하는 경우, 해당 엔드포인트의 서비스 약관과 개인정보 처리 방침이 라이브러리와 별개로 적용됩니다. NVIDIA NeMo Guardrails 라이브러리의 텔레메트리 옵트아웃은 사용자가 선택한 엔드포인트에는 적용되지 않습니다. NVIDIA Build는 평가 및 테스트 전용으로 제공되며 프로덕션 환경에서 사용해서는 안 됩니다. NVIDIA Build 사용 시 기밀 정보나 개인 데이터를 제출하지 마십시오.
## 커뮤니티 기여 초대
저장소에 있는 예제 레일은 훌륭한 시작점입니다. 신뢰할 수 있고, 안전하며, 보안이 강화된 LLM의 힘을 모든 사람이 이용할 수 있도록 하는 데 커뮤니티의 기여를 진심으로 초대합니다. 개발 환경 설정 및 NeMo Guardrails 라이브러리에 기여하는 방법에 대한 지침은 [기여 지침](https://github.com/nvidia-nemo/guardrails/blob/develop/CONTRIBUTING.md)을 참조하세요.
## 라이선스
NeMo Guardrails 라이브러리는 [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)에 따라 라이선스가 부여됩니다.
## 인용 방법
NeMo Guardrails 라이브러리를 사용하는 경우, 해당 라이브러리를 소개한 [EMNLP 2023 논문](https://aclanthology.org/2023.emnlp-demo.40)을 인용하세요.```bibtex
@inproceedings{rebedea-etal-2023-nemo,
title = "{N}e{M}o Guardrails: A Toolkit for Controllable and Safe {LLM} Applications with Programmable Rails",
author = "Rebedea, Traian and
Dinu, Razvan and
Sreedhar, Makesh Narsimhan and
Parisien, Christopher and
Cohen, Jonathan",
editor = "Feng, Yansong and
Lefever, Els",
booktitle = "Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing: System Demonstrations",
month = dec,
year = "2023",
address = "Singapore",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.emnlp-demo.40",
doi = "10.18653/v1/2023.emnlp-demo.40",
pages = "431--445",
}