Skip to main content

module cleanlab_codex.project

Module for interacting with a Codex project.


class MissingProjectError

Raised when the project ID or access key does not match any existing project.


class Project

Represents a Codex project.

To integrate a Codex project into your RAG/Agentic system, we recommend using one of our abstractions such as CodexTool. The query method can also be used directly if none of our existing abstractions are sufficient for your use case.

method __init__

__init__(
sdk_client: '_Codex',
project_id: 'str',
verify_existence: 'bool' = True
)

Initialize the Project. This method is not meant to be used directly. Instead, use the Client.get_project(), Client.create_project(), or Project.from_access_key() methods.

Args:

  • sdk_client (Codex): The Codex SDK client to use to interact with the project.
  • project_id (str): The ID of the project.
  • verify_existence (bool, optional): Whether to verify that the project exists.

property id

The ID of the project.


method add_entries

add_entries(entries: 'list[EntryCreate]')None

Add a list of entries to this Codex project. Must be authenticated with a user-level API key to use this method. See Client.create_project() or Client.get_project().

Args:

  • entries (list[EntryCreate]): The entries to add to this project. See EntryCreate.

Raises:

  • AuthenticationError: If the Project was created from a project-level access key instead of a Client instance.

classmethod create

create(
sdk_client: '_Codex',
organization_id: 'str',
name: 'str',
description: 'str | None' = None
) → Project

Create a new Codex project. This method is not meant to be used directly. Instead, use the create_project method on the Client class.

Args:

  • sdk_client (Codex): The Codex SDK client to use to create the project. This client must be authenticated with a user-level API key.
  • organization_id (str): The ID of the organization to create the project in.
  • name (str): The name of the project.
  • description (str, optional): The description of the project.

Returns:

  • Project: The created project.

Raises:

  • AuthenticationError: If the SDK client is not authenticated with a user-level API key.

method create_access_key

create_access_key(
name: 'str',
description: 'str | None' = None,
expiration: 'datetime | None' = None
)str

Create a new access key for this project. Must be authenticated with a user-level API key to use this method. See Client.create_project() or Client.get_project().

Args:

  • name (str): The name of the access key.
  • description (str, optional): The description of the access key.
  • expiration (datetime, optional): The expiration date of the access key. If not provided, the access key will not expire.

Returns:

  • str: The access key token.

Raises:

  • AuthenticationError: If the Project was created from a project-level access key instead of a Client instance.

classmethod from_access_key

from_access_key(access_key: 'str') → Project

Initialize a Project from a project-level access key.

Args:

  • access_key (str): The access key for authenticating project access.

Returns:

  • Project: The project associated with the access key.

method query

query(
question: 'str',
fallback_answer: 'Optional[str]' = None,
read_only: 'bool' = False
)tuple[Optional[str], Optional[Entry]]

Query Codex to check if this project contains an answer to the question. Add the question to the project for SME review if it does not.

Args:

  • question (str): The question to ask the Codex API.
  • fallback_answer (str, optional): Optional fallback answer to return if Codex is unable to answer the question.
  • read_only (bool, optional): Whether to query the Codex API in read-only mode. If True, the question will not be added to the Codex project for SME review. This can be useful for testing purposes when setting up your project configuration.

Returns:

  • tuple[Optional[str], Optional[Entry]]: A tuple representing the answer for the query and the existing or new entry in the Codex project. If Codex is able to answer the question, the first element will be the answer returned by Codex and the second element will be the existing Entry in the Codex project. If Codex is unable to answer the question, the first element will be fallback_answer if provided, otherwise None. The second element will be a new Entry in the Codex project.