Automating document analysis with Box AI and Document Generation

|
Share

In this article, we explore how Box AI and Document Generation API can streamline a workflow, turning unstructured movie scripts into actionable insights with minimal effort.

Introduction

Imagine you work at a movie production company that uses Box to store all their documents and content.

Every month, the producer’s assistant receives dozens of movie scripts that require creating an internal memo summarizing key script details.

This traditionally manual task is time-consuming and tedious. But what if AI could automate it?

The workshop: Hands-on with AI-powered automation

This workshop was designed with simplicity in mind, making it accessible to developers of all experience levels. It provides:

  • A working Python solution using the Box SDK
  • Pre-configured sample scripts for easy testing
  • Fully customizable code for participants to modify and explore

By the end, you will:
✅ Understand how to use Box AI extract and ask endpoints
✅ Gain experience working with Box Doc Gen
✅ Walk away with a Python project for future reference

Get started on this GitHub repo.

The use case: From movie script to summary

Imagine a production company tasked with reviewing incoming scripts. For each script, they need an internal memo that includes:

  • Basic details (title, date, genre, author)
  • A plot summary
  • Descriptions of locations and props
  • A character list with actor suggestions
  • Director and producer recommendations
  • Background information on the author (past work, production history, revenue insights)

Manually compiling this information is both labor-intensive and repetitive. The solution? Using Box AI to extract and generate this structured data automatically.

How Box AI and Doc Gen automate the process

This workshop demonstrates a hands-on, Python-based approach to automating movie script analysis with two key Box AI capabilities:

To use Box Doc Gen, you must have access to Microsoft Word, as it is required for creating and authoring your document templates. Box Doc Gen is designed to facilitate the dynamic generation of business documents, but it is important to note that Box does not have control over users’ access to Microsoft Word. Users must ensure they have the necessary permissions and access to Microsoft Word to create and author document templates effectively.

Extracting data from the movie script

The Box AI extract endpoint allows developers to provide a well-defined JSON schema. Box AI then scans the movie script and fills in the relevant details in JSON format.

This can be as easy as:

def get_ai_script_data_extract(client: BoxClient, box_file: File
) -> AiResponseFull:
    script_schema = Script().json_schema()
    properties = script_schema["allOf"][1]["properties"]
    prompt = f"{script_schema}"
    item = AiItemBase(id=box_file.id, type=AiItemBaseTypeField.FILE)
    return client.ai.create_ai_extract(prompt, [item])

Notice that I’m extracting the JSON schema directly from class Script, which is a python data class by using some clever libraries.

You can use the metadata properties of python data classes to give the AI hints on how to get the information. For example:

@dataclass_json
@dataclass
class Script(MergeBase):
    title: str = ""
    author: str = ""
    genre: str = ""
    date_written: str = ""
    date_written_iso: date = field(
        default=None, 
        metadata={"description": "script written data in iso format"}
    )
    plot_summary: str = field(
        default="",
        metadata={
            "description": "A summary of the plot of this movie script.",
        },
    )

📌 Challenge: AI extraction is not always perfect — developers need to handle missing or inaccurate data.

Generating insights beyond the script

Some required information, like actor and director suggestions, isn’t in the script. That’s where the Box AI ask endpoint comes in. By formatting the request properly, we can retrieve AI-generated recommendations in JSON format.

For example, retrieving the character list requires reading the movie script, and asking the AI which actors would it suggest for each role:

def get_ai_character_list(client: BoxClient, box_file: File
) -> AiResponseFull:
    sample_json_object = [Character.gen_sample_data()]
    mode = CreateAiAskMode.SINGLE_ITEM_QA
    prompt = (
        "read this movie script and give me a character list, "
        "(without the original actor name, just the character name) "
        "with one sentence description "
        "and suggest 5 actors for each character "
        "do not suggest the original movie actors if the movie has been already produced. "
        f"format the output this directors list in a json format using this example: {sample_json_object}"
    )
    item = AiItemBase(id=box_file.id, type=AiItemBaseTypeField.FILE)
    return client.ai.create_ai_ask(mode, prompt, [item])

The above sample data looks like this:

{
  "name": "Character A",
  "description": "Character A description",
  "suggested_actors": "Actor A, Actor B, Actor C"
}

And the output result:

"character_list": [
        {
            "name": "Ripley",
            "description": "A strong and determined survivor who has...",
            "suggested_actors": "Jessica Chastain, Charlize Theron, Emily Blunt, Kate Beckinsale, Rebecca Ferguson"
        },
        {
            "name": "Burke",
            "description": "A corporate representative with a ...",
            "suggested_actors": "Aaron Paul, John C. Reilly, Dan Stevens, Oscar Isaac, Michael Shannon"
        },

📌 Challenge: AI can make mistakes, lose context and return inaccurate data.

Creating the internal memo

Once Box AI extracts and generates the necessary data, we use the Box Document Generation API to format it into a structured, decision-ready memo.

To start we need a MS Word template, with special tags that get replaced when we merge the template with the data:

Automating document analysis with Box AI and Document Generation

The Box Doc Gen API takes in structured JSON data and merges it into a predefined document template. This allows us to create a polished internal memo that producers can quickly review.

Here is a sample of the data:

{
    "title": "Aliens",
    "author": "James Cameron",
    "genre": "Action Horror Sci-Fi Thriller",
    "date_written": "May 28, 1985",
    "date_written_iso": "1985-05-28",
    "plot_summary": "In 'Aliens,' Ellen Ripley awakens from hypersleep after...",
    "character_list": [{
            "name": "Ripley",
            "description": "A strong and determined survivor...",
            "suggested_actors": "Jessica Chastain, Charlize Theron, Emily Blunt, Kate Beckinsale, Rebecca Ferguson"
        }, {...}
    ],
    "props": [{
            "name": "Pulse Rifle",
            "description": "A standard-issue weapon for the Colonial..."
        }, {...}
    ],
    "locations": [{
            "name": "Gateway Station",
            "description": "A sprawling space station orbiting Earth..."
        }, {...}
    ],
    "producers": [{
            "name": "Jerry Bruckheimer",
            "description": "A prolific producer known for high-octane..."
        }, {...}
    ],
    "accomplishments": [{"description": "Academy Award for Best Picture for 'Titanic'"}, {...}],
    "other_scripts": [{"description": "The Terminator"}, {...}],
    "produced_movies": [{
            "title": "Titanic",
            "gross_revenue": "$2.195 billion"
        }, {...}
    ],
    "companies_worked_with": [{"description": "20th Century Fox"}, {...}]
}

📌 Best Practices for Doc Gen: Keep JSON flat — The merge engine does not support nested lists.

Merging the data with the template is also simple and straightforward. Here is the sample from the workshop:

def main() -> None:
    # Get a box client
    ap = AppConfig()
    client = ap.get_box_client()
    # Check Box API connection
    user = client.users.get_user_me()
    print("\n\n-- Box API --")
    print(f"Connected to Box API as {user.name}")
    # Get the data
    source_data, file_name = get_sample_movie_data()
    movie_data = {}

    movie_data["script"] = source_data
    print(f"Using movie data from {file_name}")

    file_reference = FileReferenceV2025R0(ap.doc_gen_template_file_id)
    destination_folder = CreateDocgenBatchV2025R0DestinationFolder(ap.merge_folder_id)
    document_data = DocGenDocumentGenerationDataV2025R0(file_name, movie_data)

    # Merger the files
    merge_batch: DocGenBatchBaseV2025R0 = client.docgen.create_docgen_batch_v2025_r0(
        file=file_reference,
        input_source="api",
        destination_folder=destination_folder,
        output_type="pdf",
        document_generation_data=[document_data],
    )
    print(f"Merge batch created: {merge_batch.id}")

The above will create a Doc Gen batch and will output a PDF like this:

Automating document analysis with Box AI and Document Generation

Automating the workflow

The automation can be triggered in multiple ways:

  • A webhook detects new script uploads in a designated Box folder.
  • A manual action within the Box web app lets users trigger processing.
  • A Box Skill integration allows seamless embedding into existing workflows.

Developers can keep this solution self-contained within Box or extend it by integrating third-party data sources.

Key learnings and considerations

Here are some insights we discovered while building this proof of concept:

🔹 Handling AI limitations: AI may fail to extract some details, so developers must account for missing data.
🔹 Fact-checking is essential: Relying solely on an LLM model is risky — use multiple sources for validation.
🔹 Data formatting matters: The JSON provided to Doc Gen should be as flat as possible; nested lists are not supported.
🔹 Script size constraints: Some scripts were too large for Box AI to process effectively.
🔹 Python makes it easy: The Box Python SDK allows this automation with just a few lines of code.

Conclusion: Unlocking AI-Powered document automation

This workshop is more than just a technical demo — it’s an invitation to explore the art of the possible. While our example focuses on movie scripts, the same principles apply across industries. Whether you’re working with legal contracts, financial reports, or research papers, Box AI and Document Generation can transform unstructured content into structured, actionable insights.

If you’re interested in automating your workflows, try this workshop and start reimagining what’s possible with Box AI and Doc Gen. 🚀