4.2 RAILファイル
RAIL File Format
RAILとは
RAIL(Reliable AI Language)は、Guardrails AI専用のXMLベースDSL。スキーマとバリデーションルールを宣言的に定義できる。
<!-- user_profile.rail -->
<rail version="0.1">
<output>
<object name="user">
<string name="name"
description="ユーザー名"
validators="length: 1 50" />
<integer name="age"
description="年齢"
validators="range: 0 150" />
<string name="email"
description="メールアドレス"
validators="regex: ^[\w\.-]+@[\w\.-]+\.\w+$" />
<list name="tags">
<string validators="length: 1 20" />
</list>
</object>
</output>
</rail>
RAILの基本要素
| 要素 | 説明 |
|---|---|
<output> | 出力スキーマのルート |
<object> | オブジェクト型(dict) |
<string> | 文字列型 |
<integer> | 整数型 |
<float> | 浮動小数点型 |
<bool> | 真偽値型 |
<list> | 配列型 |
RAILファイルの使用
from guardrails import Guard # ファイルから読み込み guard = Guard.from_rail("./schemas/user_profile.rail") # 文字列から読み込み rail_str = """ <rail version="0.1"> <output> <string name="result" /> </output> </rail> """ guard = Guard.from_rail_string(rail_str)
RAILとPydanticの使い分け
シンプルなスキーマはPydantic、複雑なスキーマや非Python環境での共有にはRAILが適している。
参考文献
[1] Guardrails AI - RAIL - https://docs.guardrailsai.com/concepts/rail/
[1] Guardrails AI - RAIL - https://docs.guardrailsai.com/concepts/rail/