Skip to main content

Lightspeed Providers

Custom provider implementations for Llama Stack that extend the capabilities of AI applications with specialized safety and content filtering features.

Overview

This repository contains custom providers for Llama Stack, including:

  • Question Validity Shield: Ensures queries are related to OpenShift/Ansible topics (It can be Configured for other Platforms).
  • Redaction Shield: Automatically detects and redacts sensitive information from user messages
  • Additional safety and content filtering providers

Building and publishing

Manual procedure, assuming an existing PyPI API token available:

## Generate distribution archives to be uploaded into Python registry
pdm run python -m build
## Upload distribution archives into Python registry
pdm run python -m twine upload --repository ${PYTHON_REGISTRY} dist/*

Features

Redaction Shield

  • Pattern-based redaction: YAML-configurable regex patterns for flexible content filtering
  • Automatic detection: Detects credit card numbers, API keys, tokens, passwords, and custom patterns

Question Validity Shield

  • Topic validation: Ensures queries are related to specified topics (OpenShift/Ansible) (It can be configured for other Platforms)
  • LLM-powered classification: Uses AI to determine query relevance
  • Customizable responses: Configure custom messages for invalid queries

Quick Start

Prerequisites

  • Python >= 3.12
  • Llama Stack == 0.4.3
  • pydantic >= 2.10.6

Installation

  1. Clone the repository

    git clone https://github.com/lightspeed-core/lightspeed-providers.git
    cd lightspeed-providers
    
  2. Install dependencies

    pip install -e .
    
  3. Install Llama Stack (if not already installed)

    pip install llama-stack
    

Make targets

Usage: make <OPTIONS> ... <TARGETS>

Available targets are:

install                           Install all dependencies using uv
test                              Run the unit tests
test-unit                         Run the unit tests
test-e2e                          Run end to end tests for the service
test-solr                         Run Solr vector_io tests
check-types                       Checks type hints in sources
security-check                    Check the project for security issues
lint                              Lint source code, including tests
format                            Format the code into unified format
shellcheck                        Run shellcheck
black                             Check source code using Black code formatter
pylint                            Check source code using Pylint static code analyser
pyright                           Check source code using Pyright static type checker
docstyle                          Check the docstring style using Docstyle checker
ruff                              Check source code using Ruff linter
verify                            Run all linters
clean                             Clean build artifacts
build                             Build package
help                              Show this help screen

Local Setup

Method 1: Using with Existing Llama Stack

  1. Install the Python package
    pip install lightspeed_stack_providers
    
  2. Configure your run.yaml (see Configuration section below)

Configuration

1. Register External Providers

Add to your run.yaml file:

# External providers configuration
external_providers_dir: ${env.EXTERNAL_PROVIDERS_DIR:/providers.d}

# Changes in the providers

providers:
  safety:
  - provider_id: llama-guard
    provider_type: inline::llama-guard
    config:
      excluded_categories: []

# For Redaction shields

  - provider_id: lightspeed_redaction
    provider_type: inline::lightspeed_redaction
    config:
        case_sensitive: false
        rules:
          - pattern: "(?i)(password|passwd)[\\s:=]+[^\\s]+"
            replacement: "[REDACTED_PASSWORD]"
          
          - pattern: "(?i)(registry|image):\\s*([\\w\\d\\.-]+)(:[\\w\\d\\.-]+)?"
            replacement: "\\1: [REDACTED_IMAGE]"
          
          - pattern: "(?i)(url|endpoint):\\s*https?://[\\w\\.-]+(:\\d+)?(/[\\w\\d\\.-]*)*"
            replacement: "\\1: [REDACTED_URL]"

        
          - pattern: "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b"
            replacement: "[REDACTED_IP]"
        
          - pattern: "(?i)(api_key|secret)[\\s:=]+[a-zA-Z0-9\\-_]{16,}"
            replacement: "[REDACTED_SECRET]"
          
          - pattern: "(?i)(ssh-rsa|ssh-ed25519)\\s+[A-Za-z0-9+/=]+"
            replacement: "[REDACTED_SSH_KEY]"

# for question validity 

  - provider_id: lightspeed_question_validity
    provider_type: inline::lightspeed_question_validity
    config:
      model_id: ${env.INFERENCE_MODEL}
      model_prompt: |-
        Instructions:
        - You are a question classifying tool
        - You are an expert in ansible
        - Your job is to determine where or a user's question is related to ansible technologies and to provide a one-word response
        - If a question appears to be related to ansible technologies, answer with the word ${allowed}, otherwise answer with the word ${rejected}
        - Do not explain your answer, just provide the one-word response


        Example Question:
        Why is the sky blue?
        Example Response:
        ${rejected}

        Example Question:
        Can you help generate an ansible playbook to install an ansible collection?
        Example Response:
        ${allowed}

        Example Question:
        Can you help write an ansible role to install an ansible collection?
        Example Response:
        ${allowed}

        Question:
        ${message}
        Response:
        invalid_question_response: |-
        Hi, I'm the Ansible Lightspeed Intelligent Assistant, I can help you with questions about Ansible,
        please ask me a question related to Ansible.

# changes in the agents : 

shields:
  - shield_id: lightspeed_question_validity-shield
    provider_id: lightspeed_question_validity
  - shield_id: redaction-shield
    provider_id: lightspeed_redaction
    provider_shield_id: lightspeed-redaction-shield

Usage Examples

Testing Redaction

# Test the redaction shield
curl -X POST "http://localhost:8321/v1/safety/run-shield" \
  -H "Content-Type: application/json" \
  -d '{
    "shield_id": "redaction-shield",
    "messages": [
      {
        "role": "user",
        "content": "My API key is abc123xyz and password is secret456"
      }
    ]
  }'

Adding New Providers

  1. Create provider directory
    mkdir -p ./providers.d/inline/safety/
    curl -o ./providers.d/inline/safety/lightspeed_question_validity.yaml https://raw.githubusercontent.com/lightspeed-core/lightspeed-            providers/refs/heads/main/resources/external_providers/inline/safety/lightspeed_question_validity.yaml
    curl -o ./providers.d/inline/safety/lightspeed_question_validity.yaml https://raw.githubusercontent.com/lightspeed-core/lightspeed-            providers/refs/heads/main/resources/external_providers/inline/safety/lightspeed_redaction.yaml   
    
  2. Add external provider definition
    # resources/external_providers/your_provider.yaml
    module: lightspeed_stack_providers.providers.inline.safety.your_provider
    config_class: lightspeed_stack_providers.providers.inline.safety.your_provider.config.YourProviderConfig
    pip_packages: ["lightspeed_stack_providers"]
    api_dependencies:
      - safety
    

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lightspeed_stack_providers-0.5.4.tar.gz (52.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lightspeed_stack_providers-0.5.4-py3-none-any.whl (64.5 kB view details)

Uploaded Python 3

File details

Details for the file lightspeed_stack_providers-0.5.4.tar.gz.

File metadata

  • Download URL: lightspeed_stack_providers-0.5.4.tar.gz
  • Upload date:
  • Size: 52.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lightspeed_stack_providers-0.5.4.tar.gz
Algorithm Hash digest
SHA256 5848530b6c0b0910bfa84fad6994f9b4c96170b517c61c449c2632b696ac7fe9
MD5 4307a5204968ff4d4bc1a46d1dae7e8b
BLAKE2b-256 2815c169089e6c961452f49230821543a1bc32de139b99b7a66c6445b597d7bf

See more details on using hashes here.

File details

Details for the file lightspeed_stack_providers-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: lightspeed_stack_providers-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 64.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lightspeed_stack_providers-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 20ddbece9ab1eff872cd7a7ec15f544ded3e1f3902b56b37bbd1cd125253f686
MD5 fcb409031d66ad6ec0525f98e30f5395
BLAKE2b-256 3afea161650c83c02bb56b566dda8877c93bf3478fe80d51707f09dfa0829cbb

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.3

2 files

0.6.2

2 files

This release

0.5.4 This release

2 files

0.5.3

2 files

0.5.0

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.1.18

2 files

0.1.17

2 files

0.1.16

2 files

0.1.15

2 files

0.1.14

2 files

0.1.13

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page