File size: 847 Bytes
9748a61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Guardrails RAIL schema and helpers for structured legal answers.
"""

from __future__ import annotations

from functools import lru_cache
from pathlib import Path
from typing import Dict, Optional

from guardrails import Guard

SCHEMA_DIR = Path(__file__).resolve().parent / "schemas"
RAIL_PATH = SCHEMA_DIR / "legal_answer.rail"


@lru_cache(maxsize=1)
def get_legal_guard() -> Guard:
    """Return cached Guard instance for legal answers."""

    return Guard.from_rail(rail_file=str(RAIL_PATH))


def ensure_schema_files() -> Optional[Dict[str, str]]:
    """
    Return metadata for the legal RAIL schema to help packaging.

    Called during setup to make sure the schema file is discovered by tools
    such as setup scripts or bundlers.
    """

    if RAIL_PATH.exists():
        return {"legal_rail": str(RAIL_PATH)}
    return None