GABRIEL (Generalized Attribute Based Ratings Information Extraction Library)

repository·main·Indexed 19 days ago

https://github.com/openai/gabriel

A Python library (v1.1.9) designed to transform unstructured qualitative data—including text, images, and audio—into structured datasets using GPT models. GABRIEL provides tools for measuring quantitative attributes via `gabriel.rate`, performing structured extraction, classification, and ranking, as well as data cleaning tasks like deduplication and de-identification. It includes operational tooling for batching, parallelization, checkpointing, and auditing large-scale LLM-based measurement workflows.

Tokens
11.2K
Snippets
28
Records
41
Agent score
64%

What's inside openai-gabriel

  1. Customize prompts and model routing

    main

    You can refine how GABRIEL interacts with models using these options:

    • additional_instructions: Add clarifications to the prompt (e.g., to mandate that labels must be mutually exclusive).
    • template_path: Provide a custom Jinja template path while maintaining built-in retries and checkpoints.
    • gabriel.whatever: Use this for fully custom prompts, attachments, or specific routing logic.
  2. Configure modalities and web search

    main

    Most measurement helpers allow you to specify the data type via the modality parameter. Supported values include:

    • text
    • entity
    • pdf
    • image
    • audio
    • web

    Web Search: Set web_search=True to allow GPT to gather context from the web before performing a rating or extraction.

    Image Detail: For image understanding, use the image_detail parameter with one of the following values:

    • low
    • high
    • original
    • auto

    Audio: Audio inputs are routed through Chat Completions. As of July 2026, use the gpt-audio-1.5 model slug; gpt-audio-mini is deprecated.

  3. Manage saving, logging, and resuming runs

    main

    GABRIEL manages outputs and checkpoints through the save_dir parameter (which supports tilde ~ and environment variables).

    • Outputs: Each run writes cleaned outputs and checkpoints raw calls in files like *_raw_responses.csv.
    • Resuming: To resume a compatible partial run, set reset_files=False.
    • Starting Fresh: If your research specification or prompt changes, use a fresh directory or set reset_files=True to prevent mixing old responses with new ones.
    • Auditing: Use gabriel.view to perform quick spot checks on results.
  4. Best practices for scaling and reliability

    main

    When running large-scale workloads with GABRIEL, follow these operational guidelines:

    Model Selection

    • Luna is a recommended starting point for many applications and large-scale work.
    • For subtle, knowledge-heavy, or writing-sensitive tasks, pilot Terra or Sol on representative samples.
    • Note: Always verify model slugs (e.g., gpt-5.6-luna) against the official OpenAI model catalog, as IDs change.

    Concurrency and Throughput

    • Use n_parallels=650 as a ceiling. GABRIEL automatically manages rate limits, retries, and concurrency adjustments.
    • Do not lower this value for small tests; it is a ceiling, not a fixed worker count.

    Workflow Pattern: Pilot, Checkpoint, Scale

    1. Pilot: Test a representative sample and inspect raw responses and output shapes.
    2. Checkpoint: Use reset_files=False to resume compatible runs if they fail or are interrupted.
    3. Scale: Use a new save_dir whenever you change the model, prompt, fields, or labels.
  5. Install development dependencies and run tests

    main

    To set up a development environment with linting (ruff, mypy) and run the test suite:

    pip install -e .[dev]
    pytest

    Note: Tests use built-in dummy responses, so an API key is not required for testing.

  6. Install the GABRIEL library

    main

    You can install GABRIEL from PyPI or directly from the GitHub repository. After installation, you can use it in your Python environment by running import gabriel.

    Prerequisites

    Before running any GABRIEL functions, you must set your OpenAI API key as an environment variable:

    export OPENAI_API_KEY="sk-..."

    If you are using Google Colab, store the key in Secrets under the name OPENAI_API_KEY and access it via google.colab.userdata.

    pip install openai-gabriel
    
    # or install directly from GitHub
    pip install \
      --force-reinstall \
      git+https://github.com/openai/GABRIEL.git@main
  7. Understand the output format of the Codify task

    main

    The run method returns a pd.DataFrame that includes the original data plus new columns based on the mode used:

    • In Static Mode (when categories is provided): A new column is created for each category key provided in the categories dictionary. Each cell in these columns contains a List[str] of snippets that matched that category.
    • In Dynamic Mode (when categories is None): A single new column named coded_passages is added. Each cell contains a dictionary where keys are the discovered categories and values are List[str] of snippets.

    Example of coded_passages structure in Dynamic Mode:

    # Resulting row in df_proc['coded_passages']
    {
        "entity_type": ["Apple", "Microsoft"],
        "location": ["Cupertino", "Redmond"]
    }
  8. How to use existing mappings for warm starts or manual edits

    main

    The Deidentifier supports a powerful workflow for refining de-identification without repeated LLM costs:

    1. Warm Start: Provide a mapping_column containing dictionaries of { "real_form": { "casted form": "...", "real forms": [...] } }. The task will load the first non-empty mapping found for each group and use it as the starting point for the LLM.
    2. Manual Refinement:
      • Run the task once to generate a mapping.
      • Manually edit the resulting mapping column in your CSV/DataFrame to correct any errors.
      • Rerun the task with use_existing_mappings_only=True. This will skip all LLM calls and simply apply your corrected mappings to the text.
  9. Measurement primitives in GABRIEL

    main

    GABRIEL provides several core functions for measuring and extracting information from qualitative data:

    • gabriel.rate: Assigns 0–100 scores per attribute across various modalities (text, entities, images, audio, or web-sourced context).
    • gabriel.rank: Performs pairwise tournaments to surface relative winners with grounded z-scores.
    • gabriel.classify: Performs single- or multi-label tagging using label definitions and produces consensus columns.
    • gabriel.extract: Extracts typed fields or multiple entities from sources like passages, pages, images, PDFs, or audio items. Note that one source may produce multiple rows.
    • gabriel.discover: Contrasts two labeled corpora to identify discriminating features.
  10. Data preparation and cleanup tools

    main

    GABRIEL includes helpers for cleaning and preparing datasets:

    • gabriel.load: Converts folders of media into spreadsheets containing clean IDs and file paths.
    • gabriel.merge: Performs fuzzy joins using embeddings and GPT checks.
    • gabriel.deduplicate: Produces de-duplicated lists using embeddings and GPT checks.
    • gabriel.filter: Screens large candidate lists using natural-language conditions.
    • gabriel.deidentify: Replaces PII (Personally Identifiable Information) with realistic stand-ins to protect privacy.
  11. Qualitative coding and review tools

    main

    For qualitative research workflows, use the following tools:

    • gabriel.codify: Highlights snippets that match specific qualitative codes.
    • gabriel.view: A UI-based tool for auditing results, often paired with codify.
    • gabriel.compare: Contrasts paired items (such as drafts, policies, or campaigns) to identify concise similarities and differences.
    • gabriel.bucket: Proposes bucket names and definitions from a large term universe. This creates a taxonomy that can be used for subsequent classify steps.
  12. Ideation and custom prompt execution

    main

    To generate new content or run bespoke logic:

    • gabriel.ideate and gabriel.seed: Generate diverse candidates for further measurement.
    • gabriel.whatever: Runs bespoke prompts with support for custom response_fn or web search. It reuses the library's core infrastructure for retries, logging, and checkpointing.