Skip to main content

ai-risk-extractor

PyPI version License: MIT Downloads LinkedIn

ai-risk-extractor is a lightweight Python package that extracts structured risk insights from free‑form user prompts about autonomous AI agents, task injection, AI agency, and related vulnerabilities. By leveraging a language model (default ChatLLM7), the package parses the input text and returns a standardized, machine‑readable summary that highlights threat levels, involved components, and possible exploitation methods.

Installation

pip install ai_risk_extractor

Quick Start

from ai_risk_extractor import ai_risk_extractor

# Example user prompt describing an AI risk scenario
prompt = """
An autonomous AI assistant receives a hidden instruction from a malicious user
that causes it to execute a privileged system command. The instruction is
embedded in a seemingly harmless chat message.
"""

# Extract structured risk information (uses default ChatLLM7)
risk_summary = ai_risk_extractor(user_input=prompt)

print(risk_summary)

Function Signature

def ai_risk_extractor(
    user_input: str,
    api_key: Optional[str] = None,
    llm: Optional[BaseChatModel] = None,
) -> List[str]:
    """
    Process `user_input` with a language model and return extracted risk data.

    Parameters
    ----------
    user_input: str
        The free‑form text describing AI scenarios or concerns.
    api_key: Optional[str]
        API key for the default `ChatLLM7`. If omitted, the function will
        read the `LLM7_API_KEY` environment variable. If that is also missing,
        a placeholder key `"None"` is used (the request will still be routed
        to the LLM7 endpoint).
    llm: Optional[BaseChatModel]
        Any LangChain `BaseChatModel` instance. If omitted, `ChatLLM7` from
        `langchain_llm7` is instantiated automatically.

    Returns
    -------
    List[str]
        A list of extracted data strings that match the internal regex pattern.
    """

Using a Custom LLM

You can provide any LangChain‑compatible chat model instead of the default ChatLLM7.

OpenAI (e.g., GPT‑4)

from langchain_openai import ChatOpenAI
from ai_risk_extractor import ai_risk_extractor

my_llm = ChatOpenAI(model="gpt-4")
result = ai_risk_extractor(user_input=prompt, llm=my_llm)

Anthropic (e.g., Claude)

from langchain_anthropic import ChatAnthropic
from ai_risk_extractor import ai_risk_extractor

my_llm = ChatAnthropic(model="claude-2.1")
result = ai_risk_extractor(user_input=prompt, llm=my_llm)

Google Generative AI

from langchain_google_genai import ChatGoogleGenerativeAI
from ai_risk_extractor import ai_risk_extractor

my_llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro")
result = ai_risk_extractor(user_input=prompt, llm=my_llm)

API Key & Rate Limits

The default ChatLLM7 free tier provides generous rate limits suitable for most development and research workflows. If you need higher limits, obtain a personal API key by registering at:

https://token.llm7.io/

Provide the key either:

  • via the LLM7_API_KEY environment variable, or
  • directly as the api_key argument:
result = ai_risk_extractor(user_input=prompt, api_key="YOUR_LLM7_API_KEY")

Contributing

Contributions, suggestions, and bug reports are welcome! Feel free to open a pull request or discuss enhancements.

Issues

If you encounter any problems, please open an issue on GitHub:

https://github.com/chigwell/ai_risk_extractor/issues

License

This project is licensed under the MIT License.

Author

Eugene Evstafev
Email: hi@euegne.plus
GitHub: @chigwell

Metadata

Release files for ai-risk-extractor 2025.12.21102659

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ai-risk-extractor 2025.12.21102659
File Size Uploaded
ai_risk_extractor-2025.12.21102659.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ai-risk-extractor 2025.12.21102659
File Interpreter ABI Platform
ai_risk_extractor-2025.12.21102659-py3-none-any.whl Python 3 none any Details

Total release size: 9.7 kB

Release files / ai_risk_extractor-2025.12.21102659.tar.gz

Download URL ai_risk_extractor-2025.12.21102659.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7322184183402fc3346b91a80e8b0606f22eeff72d93ed8174c28082aa236ea9
BLAKE2b-256 checksum
How to use checksums
8412f4ec8d3e68620a0f4f92005ef61acf52db8dc631eaf004d83164f5cb8a2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release files / ai_risk_extractor-2025.12.21102659-py3-none-any.whl

Download URL ai_risk_extractor-2025.12.21102659-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5eee2345a2e25fdd78e914bac49e61180a94fc0b02ea4481e5fb4e9948e235f9
BLAKE2b-256 checksum
How to use checksums
1ff77fa57e7fea1eb0a8d05872056ca65773bc84af6b918c8d8e9286467830cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

2025.12.21102659 This release

2 release 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