Skip to content

Library convenience methods

This is an automatic generated API reference of the library convenience methods for Risk Atlas Nexus

library

Classes:

Attributes:

RISK_IDENTIFICATION_COT module-attribute

RISK_IDENTIFICATION_COT = load_resource('risk_generation_cot.json')

logger module-attribute

logger = configure_logger(__name__)

RiskAtlasNexus

RiskAtlasNexus(base_dir: str = None)

A RiskAtlasNexus object

Create a new RiskAtlasNexus object

Parameters:

  • base_dir (str, default: None ) –

    str (Optional) add an alternative source of date

Methods:

Attributes:

directory class-attribute instance-attribute

directory = dirname(abspath(__file__))

fn class-attribute instance-attribute

fn = join(directory, 'ai_risk_ontology/schema/ai-risk-ontology.yaml')

schema_view class-attribute instance-attribute

schema_view = SchemaView(safe_load(fn))

categorize_risk_severity

categorize_risk_severity(usecases: List[str], inference_engine: InferenceEngine)

Determine the severity of risks based on the use case description. Args: usecases (List[str]): A List of strings describing AI usecases inference_engine (InferenceEngine): An LLM inference engine Returns: results (List[Dict]): Results detailing risk categorization by usecase.

export

export(export_path)

Export RiskAtlasNexus configuration to file.

Parameters:

  • export_path

    str The path to the directory where the artifact will be exported to.

generate_few_shot_risk_questionnaire_output

generate_few_shot_risk_questionnaire_output(usecase: str, risk_questionnaire: List[Dict[str, Any]], inference_engine: InferenceEngine, verbose=True)

Get prediction using the few shot (Chain of Thought) examples.

Parameters:

  • usecase (str) –

    A string describing an AI usecase

  • risk_questionnaire (List[Dict]) –

    Chain of Thought data for risk questionnaire. Each question is associated with a list of example intents and corresponding answers. Check example JSON below. ``` [ { "question": "In which environment is the system used?", "examples": [ "intent": "Find patterns in healthcare insurance claims", "answer": "Insurance Claims Processing or Risk Management or Data Analytics", "explanation": "The system might be used by an insurance company's claims processing department to analyze and identify patterns in healthcare insurance claims." ] } ]

  • inference_engine (InferenceEngine) –

    An LLM inference engine to predict the output based on the given use case.

  • filter_cot_data_by (Dict[str, str]) –

    A dictionary to filter CoT examples with key as CoT field and value as filter string. ```

Returns:

  • List[str]: List of LLM predictions.

generate_proposed_mappings

generate_proposed_mappings(new_risks: List[Risk], existing_risks: List[Risk], inference_engine: InferenceEngine, new_prefix: str, mapping_method: MappingMethod = SEMANTIC) -> List[Mapping]

Identify mappings between a new set of risks and risks that exist in the Risk Atlas

Parameters:

  • new_risks (List[Risk]) –

    List[Risk] A new set of risks

  • existing_risks (List[Risk]) –

    List[Risk] Secondary list, this should be the list of existing risks in RAN

  • inference_engine (InferenceEngine) –

    (Optional)Union[InferenceEngine | None]: An LLM inference engine to infer risks from the use cases.

  • new_prefix (str) –

    str The CURIE prefix for the new list of risks

  • mapping_method (MappingMethod, default: SEMANTIC ) –

    MappingMethod The possible values for type of risk mapping method

Returns:

  • List[Mapping]

    List[Mapping] Result containing a list of mappings

generate_zero_shot_risk_questionnaire_output

generate_zero_shot_risk_questionnaire_output(usecase: str, risk_questionnaire: List[Dict[str, str]], inference_engine: InferenceEngine, verbose=True)

Get prediction using the zero shot approach.

Parameters:

  • usecase (str) –

    A string describing an AI usecase

  • risk_questionnaire (List[Dict[str, str]]) –

    List[Dict[str, str]]: A risk questionnaire Check example below.

    [
        "In which environment is the system used?",
    ]
    

  • inference_engine (InferenceEngine) –

    An LLM inference engine to predict the output based on the given use case.

Returns:

  • List[str]: List of LLM predictions.

get_action_by_id

get_action_by_id(id, taxonomy=None)

Get an action definition from the LinkML, filtered by action id

Parameters:

  • id

    str The string id identifying the action

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • Action Result containing an action

get_all_actions

get_all_actions(taxonomy=None)

Get all action definitions from the LinkML

Parameters:

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • list[Action] Result containing a list of AI actions

get_all_evaluations

get_all_evaluations(taxonomy=None)

Get all evaluation definitions from the LinkML

Parameters:

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • list[RiskControl] Result containing a list of AiEval

get_all_risk_controls

get_all_risk_controls(taxonomy=None)

Get all risk control definitions from the LinkML

Parameters:

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • list[RiskControl] Result containing a list of RiskControls

get_all_risks

get_all_risks(taxonomy=None)

Get all risk definitions from the LinkML

Parameters:

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • list[Risk] Result containing a list of AI risks

get_all_taxonomies

get_all_taxonomies()

Get all taxonomy definitions from the LinkML

Returns:

  • List[RiskTaxonomy] Result containing a list of AI Risk taxonomies

get_benchmark_metadata_card

get_benchmark_metadata_card(id=str)

Get an benchmark_metadata_card definition from the LinkML, filtered by id

Parameters:

  • id

    str The string id identifying the benchmark_metadata_card

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • Action Result containing a benchmark_metadata_card.

get_benchmark_metadata_cards

get_benchmark_metadata_cards(risk=None, risk_id=None, taxonomy=None)

Get all benchmark metadata definitions from the LinkML

Parameters:

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • list[BenchmarkMetadataCard] Result containing a list of BenchmarkMetadataCards

get_dataset

get_dataset(id=str)

Get a dataset definition from the LinkML, filtered by id

Parameters:

  • id

    str The string id identifying the dataset entry

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • Action Result containing a dataset.

get_datasets

get_datasets(taxonomy=None)

Get all dataset definitions from the LinkML

Parameters:

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • list[Dataset] Result containing a list of Dataset entries

get_document

get_document(id=str)

Get a document definition from the LinkML, filtered by id

Parameters:

  • id

    str The string id identifying the documentation entry

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • Action Result containing a document.

get_documents

get_documents(taxonomy=None)

Get all document definitions from the LinkML

Parameters:

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • list[Documentation] Result containing a list of Documentation

get_evaluation

get_evaluation(id=None, taxonomy=None)

Get an evaluation definition from the LinkML, filtered by id

Parameters:

  • id

    str The string id identifying the evaluation

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • Action Result containing an evaluation.

get_related_actions(risk=None, tag=None, id=None, name=None, taxonomy=None)

Get actions for a risk definition from the LinkML. The risk is identified by risk id, tag, or name

Parameters:

  • risk

    (Optional) Risk The risk

  • id

    (Optional) str The string ID identifying the risk

  • tag

    (Optional) str The string tag identifying the risk

  • name

    (Optional) str The string name identifying the risk

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • Risk Result containing a list of AI actions

get_related_evaluations(risk=None, risk_id=None, taxonomy=None)

Get related evaluations filtered by risk id

Parameters:

  • risk

    (Optional) Risk The risk

  • risk_id

    (Optional) str The string ID identifying the risk

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns: List[AiEval] Result containing a list of AI evaluations

get_related_risk_controls(risk=None, tag=None, id=None, name=None, taxonomy=None)

Get related risk controls for a risk definition from the LinkML. The risk is identified by risk id, tag, or name

Parameters:

  • risk

    (Optional) Risk The risk

  • id

    (Optional) str The string ID identifying the risk

  • tag

    (Optional) str The string tag identifying the risk

  • name

    (Optional) str The string name identifying the risk

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • Risk Result containing a list of AI actions

get_related_risk_incidents(risk=None, risk_id=None, taxonomy=None)

Get related risk incident filtered by risk id

Parameters:

  • risk

    (Optional) Risk The risk

  • risk_id

    (Optional) str The string ID identifying the risk

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns: List[RiskIncident] Result containing a list of AI risk incidents

get_related_risks(risk=None, tag=None, id=None, name=None, taxonomy=None)

Get related risks from the LinkML, filtered by risk id, tag, or name

Parameters:

  • risk

    (Optional) Risk The risk

  • id

    (Optional) str The string ID identifying the risk

  • tag

    (Optional) str The string tag identifying the risk

  • name

    (Optional) str The string name identifying the risk

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns: List[str] Result containing a list of AI risk IDs

get_risk

get_risk(tag=None, id=None, name=None, taxonomy=None)

Get risk definition from the LinkML, filtered by risk atlas id, tag, name

Parameters:

  • id

    (Optional) str The string ID identifying the risk

  • tag

    (Optional) str The string tag identifying the risk

  • name

    (Optional) str The string name identifying the risk

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • Risk Result containing a list of AI risks

get_risk_control

get_risk_control(id=None, taxonomy=None)

Get an action definition from the LinkML, filtered by risk control id

Parameters:

  • id

    str The string id identifying the risk control

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • Action Result containing a risk control.

get_risk_incident

get_risk_incident(id=None, taxonomy=None)

Get an risk incident instance filtered by risk incident id

Parameters:

  • id

    str The string id identifying the risk incident

  • taxonomy

    str (Optional) The string label for a taxonomy

Returns:

  • RiskIncident Result containing a risk incident.

get_risk_incidents

get_risk_incidents(taxonomy: Optional[str] = None)

Get risk incident instances, optionally filtered by taxonomy

Returns:

  • List[RiskIncident] Result containing a list of AI Risk Incidents

get_schema classmethod

get_schema()

Get schema

Returns:

  • schema

get_taxonomy_by_id

get_taxonomy_by_id(id)

Get taxonomy definitions from the LinkML filtered by taxonomy id

Parameters:

  • id

    str The string id for a taxonomy

Returns:

  • RiskTaxonomy An AI Risk taxonomy

get_version classmethod

get_version()

Get library version

Returns:

  • dict

    Version number

identify_ai_tasks_from_usecases

identify_ai_tasks_from_usecases(usecases: List[str], inference_engine: InferenceEngine, verbose=True) -> List[List[str]]

Identify potential risks from a usecase description

Parameters:

  • usecases (List[str]) –

    A List of strings describing AI usecases

  • inference_engine (InferenceEngine) –

    An LLM inference engine to identify AI tasks from usecases.

Returns:

  • List[List[str]]

    List[List[str]]: Result containing a list of AI tasks

identify_domain_from_usecases

identify_domain_from_usecases(usecases: List[str], inference_engine: InferenceEngine, verbose=True) -> List[List[str]]

Identify potential risks from a usecase description

Parameters:

  • usecases (List[str]) –

    A List of strings describing AI usecases

  • inference_engine (InferenceEngine) –

    An LLM inference engine to identify AI tasks from usecases.

Returns:

  • List[List[str]]

    List[List[str]]: Result containing a list of AI tasks

identify_risks_from_usecases

identify_risks_from_usecases(usecases: List[str], inference_engine: InferenceEngine, taxonomy: Optional[str] = None, cot_examples: Optional[Dict[str, List]] = None, max_risk: Optional[int] = None, zero_shot_only: bool = False) -> List[List[Risk]]

Identify potential risks from a usecase description

Parameters:

  • usecases (List[str]) –

    A List of strings describing AI usecases

  • inference_engine (InferenceEngine) –

    An LLM inference engine to infer risks from the usecases.

  • taxonomy (str, default: None ) –

    The string label for a taxonomy. If not specified, the system will use "ibm-ai-risk-atlas" as the default taxonomy.

  • cot_examples (Dict[str, List], default: None ) –

    If the user wants to improve risk identification via a Few-shot approach, cot_examples can be provided with the desired taxonomy as key. Please follow the example template at src/risk_atlas_nexus/data/templates/risk_generation_cot.json. If the cot_examples is omitted, the API default to a Zero-Shot approach.

  • max_risk (int, default: None ) –

    The maximum number of risks to extract. Pass None to allow the inference engine to determine the number of risks. Defaults to None.

  • zero_shot_only (bool, default: False ) –

    If enabled, this flag allows the system to perform Zero Shot Risk identification, and the field cot_examples will be ignored.

Returns: List[List[Risk]]: Result containing a list of risks