Implementation:Protectai Llm guard Create app
Appearance
| Knowledge Sources | |
|---|---|
| Domains | API_Design, Web_Development, DevOps |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
Concrete tool for constructing the LLM Guard FastAPI application with all middleware, routes, and scanners configured, provided by the LLM Guard API server.
Description
The create_app function is the FastAPI application factory. It loads configuration from a YAML file (path from CONFIG_FILE env var), initializes scanner pipelines, configures authentication, rate limiting, CORS middleware, OpenTelemetry instrumentation, and registers all scanning API routes.
Usage
Called by Uvicorn at server startup. Not typically imported by end users directly.
Code Reference
Source Location
- Repository: llm-guard
- File: llm_guard_api/app/app.py
- Lines: L57-88
Signature
def create_app() -> FastAPI:
"""
Create and configure the LLM Guard FastAPI application.
Reads CONFIG_FILE env var (default: ./config/scanners.yml).
Initializes scanners, middleware, routes, and observability.
Returns:
Fully configured FastAPI application instance.
"""
Import
from llm_guard_api.app.app import create_app
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| CONFIG_FILE (env var) | str | No | Path to YAML config (default: ./config/scanners.yml) |
Outputs
| Name | Type | Description |
|---|---|---|
| app | FastAPI | Fully configured FastAPI application with routes and middleware |
Usage Examples
Uvicorn Startup
# Start the API server
uvicorn app.app:create_app --host=0.0.0.0 --port=8000 --workers=4
Docker Compose
services:
llm_guard_api:
build: .
ports:
- "8000:8000"
volumes:
- ./config:/home/user/app/config
environment:
- CONFIG_FILE=./config/scanners.yml
- APP_WORKERS=1
Related Pages
Implements Principle
Requires Environment
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment