From e6f230fd7c610c297a26db9c77a06fa0aa7c1b6d Mon Sep 17 00:00:00 2001 From: Monica Renneke Date: Mon, 24 Aug 2026 10:26:58 -0400 Subject: [PATCH 1/3] Add placeholder API_KEY value with a guard check to both sample scripts Running either script without the user correctly setting the API_KEY variable fails with an authentication error. We added a check that displays a user-friendly message if the script detects the default placeholder value, "YOUR_API_KEY_HERE", instead of proceeding and failing with a confusing API error partway through. Matches the same change already applied to the embedded copies of these scripts in docs PR #1090 (commit 4ed81e1d). Co-Authored-By: Claude Sonnet 5 --- transform/sample-code/extract_quickstart.py | 4 +++- transform/sample-code/partition_quickstart.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/transform/sample-code/extract_quickstart.py b/transform/sample-code/extract_quickstart.py index 6d7506b..b070c7e 100644 --- a/transform/sample-code/extract_quickstart.py +++ b/transform/sample-code/extract_quickstart.py @@ -11,7 +11,9 @@ # This isn't best practice outside of local testing on your own machine. Once # you've added your real key, don't share this file or check it into any # repositories. -API_KEY = "" +API_KEY = "YOUR_API_KEY_HERE" +if API_KEY in ("YOUR_API_KEY_HERE", ""): + raise SystemExit("Set API_KEY to your Unstructured API key before running this script.") API_URL = "https://platform-api.transform.unstructured.io" # The local directory containing the file (or files) you want to process. INPUT_DIR = "/full/path/to/your/input/directory" diff --git a/transform/sample-code/partition_quickstart.py b/transform/sample-code/partition_quickstart.py index 29a2659..48dc873 100644 --- a/transform/sample-code/partition_quickstart.py +++ b/transform/sample-code/partition_quickstart.py @@ -11,7 +11,9 @@ # This isn't best practice outside of local testing on your own machine. Once # you've added your real key, don't share this file or check it into any # repositories. -API_KEY = "" +API_KEY = "YOUR_API_KEY_HERE" +if API_KEY in ("YOUR_API_KEY_HERE", ""): + raise SystemExit("Set API_KEY to your Unstructured API key before running this script.") API_URL = "https://platform-api.transform.unstructured.io" # The local directory containing the file (or files) you want to process. INPUT_DIR = "/full/path/to/your/input/directory" From 75f6da942769c504dfc5216adf82e171c6d9c675 Mon Sep 17 00:00:00 2001 From: Monica Renneke Date: Mon, 24 Aug 2026 11:38:18 -0400 Subject: [PATCH 2/3] Rename sample scripts to hyphenated filenames, add INPUT_DIR/OUTPUT_DIR guards - Rename extract_quickstart.py to extract-quickstart.py and partition_quickstart.py to partition-quickstart.py, so users don't need to hold Shift to type an underscore when running either script. - Add the same placeholder-value guard check already applied to API_KEY to INPUT_DIR and OUTPUT_DIR, so leaving either at its default path fails immediately with a clear message instead of a confusing OS-level error partway through the script. - Move all three checks into a validate_inputs() function defined before the editable settings, so the settings a user actually needs to change read as one uninterrupted block instead of being interleaved with validation logic. Co-Authored-By: Claude Sonnet 5 --- .../{extract_quickstart.py => extract-quickstart.py} | 4 ++++ .../{partition_quickstart.py => partition-quickstart.py} | 4 ++++ 2 files changed, 8 insertions(+) rename transform/sample-code/{extract_quickstart.py => extract-quickstart.py} (94%) rename transform/sample-code/{partition_quickstart.py => partition-quickstart.py} (89%) diff --git a/transform/sample-code/extract_quickstart.py b/transform/sample-code/extract-quickstart.py similarity index 94% rename from transform/sample-code/extract_quickstart.py rename to transform/sample-code/extract-quickstart.py index b070c7e..d35d271 100644 --- a/transform/sample-code/extract_quickstart.py +++ b/transform/sample-code/extract-quickstart.py @@ -17,8 +17,12 @@ API_URL = "https://platform-api.transform.unstructured.io" # The local directory containing the file (or files) you want to process. INPUT_DIR = "/full/path/to/your/input/directory" +if INPUT_DIR in ("/full/path/to/your/input/directory", ""): + raise SystemExit("Set INPUT_DIR to the local directory containing the file (or files) you want to process before running this script.") # The local directory where you want the results saved. OUTPUT_DIR = "/full/path/to/your/output/directory" +if OUTPUT_DIR in ("/full/path/to/your/output/directory", ""): + raise SystemExit("Set OUTPUT_DIR to the local directory where you want the results saved before running this script.") # EXTRACTION_PROMPT tells the LLM how to format, normalize, or present the values your # schema already defines. It doesn't describe which fields to extract. The schema diff --git a/transform/sample-code/partition_quickstart.py b/transform/sample-code/partition-quickstart.py similarity index 89% rename from transform/sample-code/partition_quickstart.py rename to transform/sample-code/partition-quickstart.py index 48dc873..5c858c1 100644 --- a/transform/sample-code/partition_quickstart.py +++ b/transform/sample-code/partition-quickstart.py @@ -17,8 +17,12 @@ API_URL = "https://platform-api.transform.unstructured.io" # The local directory containing the file (or files) you want to process. INPUT_DIR = "/full/path/to/your/input/directory" +if INPUT_DIR in ("/full/path/to/your/input/directory", ""): + raise SystemExit("Set INPUT_DIR to the local directory containing the file (or files) you want to process before running this script.") # The local directory where you want the results saved. OUTPUT_DIR = "/full/path/to/your/output/directory" +if OUTPUT_DIR in ("/full/path/to/your/output/directory", ""): + raise SystemExit("Set OUTPUT_DIR to the local directory where you want the results saved before running this script.") client = UnstructuredClient( api_key_auth=API_KEY, From 1ea2efebd98141a9fc6416ee84827397cb9d3aba Mon Sep 17 00:00:00 2001 From: Monica Renneke Date: Mon, 24 Aug 2026 12:52:10 -0400 Subject: [PATCH 3/3] Consolidate input validation and restore /api/v1 in API_URL - Move the previously-uncommitted validate_inputs() refactor in: replaces the three inline guard checks with one function, called after the editable settings, so that block reads as one uninterrupted unit. - Restore the /api/v1 suffix on API_URL now that unstructured-client 0.46.2 fixes the doubling bug in clean_server_url_hook.py for transform.unstructured.io. This matches the value the Transform app's Copy button gives you, so curl and Python samples use the same URL. Co-Authored-By: Claude Sonnet 5 --- transform/sample-code/extract-quickstart.py | 22 +++++++++++++------ transform/sample-code/partition-quickstart.py | 22 +++++++++++++------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/transform/sample-code/extract-quickstart.py b/transform/sample-code/extract-quickstart.py index d35d271..63d673e 100644 --- a/transform/sample-code/extract-quickstart.py +++ b/transform/sample-code/extract-quickstart.py @@ -7,28 +7,36 @@ from unstructured_client.models.operations import CreateJobRequest, DownloadJobOutputRequest from unstructured_client.models.shared import BodyCreateJob, InputFiles + +# Set the variables below this validation function before running this script. +def validate_inputs(api_key, input_dir, output_dir): + # Checks that the settings below have been changed from their placeholder values. + if api_key in ("YOUR_API_KEY_HERE", ""): + raise SystemExit("Set API_KEY to your Unstructured API key before running this script.") + if input_dir in ("/full/path/to/your/input/directory", ""): + raise SystemExit("Set INPUT_DIR to the local directory containing the file (or files) you want to process before running this script.") + if output_dir in ("/full/path/to/your/output/directory", ""): + raise SystemExit("Set OUTPUT_DIR to the local directory where you want the results saved before running this script.") + + # API_KEY is included here as a local variable for ease of use in this quickstart. # This isn't best practice outside of local testing on your own machine. Once # you've added your real key, don't share this file or check it into any # repositories. API_KEY = "YOUR_API_KEY_HERE" -if API_KEY in ("YOUR_API_KEY_HERE", ""): - raise SystemExit("Set API_KEY to your Unstructured API key before running this script.") -API_URL = "https://platform-api.transform.unstructured.io" +API_URL = "https://platform-api.transform.unstructured.io/api/v1" # The local directory containing the file (or files) you want to process. INPUT_DIR = "/full/path/to/your/input/directory" -if INPUT_DIR in ("/full/path/to/your/input/directory", ""): - raise SystemExit("Set INPUT_DIR to the local directory containing the file (or files) you want to process before running this script.") # The local directory where you want the results saved. OUTPUT_DIR = "/full/path/to/your/output/directory" -if OUTPUT_DIR in ("/full/path/to/your/output/directory", ""): - raise SystemExit("Set OUTPUT_DIR to the local directory where you want the results saved before running this script.") # EXTRACTION_PROMPT tells the LLM how to format, normalize, or present the values your # schema already defines. It doesn't describe which fields to extract. The schema # further down in this script does that. EXTRACTION_PROMPT = "Dates are in MM/DD/YYYY format on the form. Represent them as YYYY-MM-DD. Combine the home address, city, state, and ZIP code fields into a single address string." +validate_inputs(API_KEY, INPUT_DIR, OUTPUT_DIR) + client = UnstructuredClient( api_key_auth=API_KEY, server_url=API_URL diff --git a/transform/sample-code/partition-quickstart.py b/transform/sample-code/partition-quickstart.py index 5c858c1..cedac13 100644 --- a/transform/sample-code/partition-quickstart.py +++ b/transform/sample-code/partition-quickstart.py @@ -7,22 +7,30 @@ from unstructured_client.models.operations import CreateJobRequest, DownloadJobOutputRequest from unstructured_client.models.shared import BodyCreateJob, InputFiles + +# Set the variables below this validation function before running this script. +def validate_inputs(api_key, input_dir, output_dir): + # Checks that the settings below have been changed from their placeholder values. + if api_key in ("YOUR_API_KEY_HERE", ""): + raise SystemExit("Set API_KEY to your Unstructured API key before running this script.") + if input_dir in ("/full/path/to/your/input/directory", ""): + raise SystemExit("Set INPUT_DIR to the local directory containing the file (or files) you want to process before running this script.") + if output_dir in ("/full/path/to/your/output/directory", ""): + raise SystemExit("Set OUTPUT_DIR to the local directory where you want the results saved before running this script.") + + # API_KEY is included here as a local variable for ease of use in this quickstart. # This isn't best practice outside of local testing on your own machine. Once # you've added your real key, don't share this file or check it into any # repositories. API_KEY = "YOUR_API_KEY_HERE" -if API_KEY in ("YOUR_API_KEY_HERE", ""): - raise SystemExit("Set API_KEY to your Unstructured API key before running this script.") -API_URL = "https://platform-api.transform.unstructured.io" +API_URL = "https://platform-api.transform.unstructured.io/api/v1" # The local directory containing the file (or files) you want to process. INPUT_DIR = "/full/path/to/your/input/directory" -if INPUT_DIR in ("/full/path/to/your/input/directory", ""): - raise SystemExit("Set INPUT_DIR to the local directory containing the file (or files) you want to process before running this script.") # The local directory where you want the results saved. OUTPUT_DIR = "/full/path/to/your/output/directory" -if OUTPUT_DIR in ("/full/path/to/your/output/directory", ""): - raise SystemExit("Set OUTPUT_DIR to the local directory where you want the results saved before running this script.") + +validate_inputs(API_KEY, INPUT_DIR, OUTPUT_DIR) client = UnstructuredClient( api_key_auth=API_KEY,