How to Create an Input Schema
A flow may require custom input when it is started. For example, it may require an email address, or a name to give to a new Globus guest collection, or some other input.
Flow authors can improve their users' experience by creating an input schema for the flow. The input schema can validate the input document that users submit when starting a flow.
Input schemas serve two purposes:
-
Before starting a flow, the Globus Flows service uses the input schema to verify that the user input meets the flow’s input requirements.
-
When starting the flow using the Globus Web App, the Web App uses the input schema to generate a graphical user interface that streamlines user input to the flow.
This overview will show you how to create an effective input schema for use with your flows.
1. A first look at input schemas
The Globus Flows service recognizes input schemas written in the JSON schema format. Here’s an example:
{
"type": "object",
"required": [
"email_address"
],
"properties": {
"email_address": {
"type": "string",
"format": "email",
"title": "Email address",
"description": "A welcome email will be sent to this address."
}
},
"additionalProperties": false
}
The input schema above ensures that when the associated flow is started, an input document must be provided that meets the following requirements:
-
The input document is a JSON object.
-
An
"email_address"
property must be specified. -
The
"email_address"
value must be a string that is formatted like an email address. -
The input document must have no other properties.
For example, the following input document would meet the schema requirements:
{
"email_address": "user@example.com"
}
The following input documents would violate the schema requirements for various reasons:
["This", "is", "an", "array"]
"email_address"
property must be present{}
"email_address"
value must be a string{
"email_address": 42
}
"movie_quote"
) are allowed{
"email_address": "user@example.com",
"movie_quote": "There is no spoon."
}
The Globus Flows service can catch many types of errors in input documents by validating the user’s input document against the flow’s input schema.
In addition, input schemas can help users start a flow using the Globus Web App, which can create a guided input GUI using the flow’s input schema.
2. The Globus Web App’s guided input form
Using the example input schema above, the Globus Web App will generate a guided input form for starting new flow runs that looks similar to this:
Notice that the Globus Web App has rendered the "title"
and "description"
properties
in the input schema to inform the user what value should be entered.
The input field has also been marked as required.
The input schema requires that the value of "email_address"
is a string,
but it also specifies that the string must match an email address format.
The Globus Web App will ensure that the user input matches the formatting.
If it doesn’t, the user will be notified of the error.
Input schemas can significantly improve the user experience when starting a flow. Let’s look at some other input field types, and introduce constraints that can help ensure user input is within expected ranges.
3. The "string"
type
"string"
is a common property type in input schemas.
It supports multiple "format"
constraints, including "email"
, which was seen above:
-
"email"
(example:user@domain.com
) -
"uuid"
(example:60ac57ef-b078-4ae5-80dc-b3b2896b3bfc
) -
"date"
(example:2023-07-10
)
{
"properties": {
"start_date": {
"type": "string",
"format": "date",
"title": "Start of date range",
"description": "Entries older than this date will not be included."
}
}
}
{
"start_date": "2023-07-10"
}
In addition to the formatting restriction above, it’s possible to specify other constraints:
-
minLength
- the minimum length of the string -
maxLength
- the maximum length of the string -
pattern
- a regular expression that the string must match
{
"properties": {
"codename": {
"type": "string",
"title": "Experiment codename",
"description": "The codename registered for the experiment.",
"minLength": 4,
"maxLength": 20
}
}
}
{
"codename": "Cinderella"
}
{
"properties": {
"beamline": {
"type": "string",
"title": "Beamline",
"description": "The beamline used for the experiment.",
"pattern": "^[1-9][0-9]?-(BM|ID)-[A-G]$"
}
}
}
{
"beamline": "10-BM-A"
}
4. The "integer"
type
"integer"
is one of the numeric types supported by input schemas.
This type supports several constraints:
-
"exclusiveMinimum"
(The user input must be greater than the exclusive minimum) -
"minimum"
(The user input must be greater than or equal to the minimum) -
"exclusiveMaximum"
(The user input must be less than the exclusive maximum) -
"maximum"
(The user input must be less than or equal to the maximum) -
"multipleOf"
(The user input must be a multiple of the multiple)
{
"properties": {
"target_certainty": {
"type": "integer",
"title": "Target certainty",
"description": "The certainty value desired for the calculation",
"minimum": 95,
"exclusiveMaximum": 100
}
}
}
{
"target_certainty": 97
}
5. The "object"
type
The input schemas above have validated flat input documents, where each key has a string or integer value. However, it’s also possible (and is often helpful) to group related properties together.
Here is a comparison of a flat input document and a nested input document:
Flat input document | Nested input document |
---|---|
|
|
Validating the nested input document requires a new type: "object"
.
This type was seen in the very first example schema at the top of the page;
in that context it mandated that the entire input document must be a JSON object.
Now it will be used to mandate that the "initial_vector"
must also be a JSON object.
Flat input schema | Nested input schema |
---|---|
|
|
If you compare this nested input schema to the flat input schema,
you will notice that the flat input schema is copied almost verbatim
as the value of the "initial_vector"
key.
The property names have changed (e.g. "initial_vector_angle"
is now simply "angle"
),
but the structure is identical.
5.1. Constraints
The "object"
type can be constrained in multiple ways.
5.1.1. Requiring known properties
By default, input schemas allow input documents to have any properties and values.
You can use the "required"
property to list properties
that must be present in the input document.
Input schema | Examples of valid input documents |
---|---|
|
|
You can — and should — mandate that specific properties are submitted
by using the "required"
property and providing an array of values.
Input schema | Examples of valid input documents |
---|---|
|
|
5.1.2. Excluding unknown properties
Just as it’s important to required specific properties,
it is often important to exclude unknown properties.
This is accomplished with the "additionalProperties"
flag, which defaults to true
.
Input schema | Examples of valid input documents |
---|---|
|
|
It is common practice to exclude unknown properties
by setting "additionalProperties"
to false
:
Input schema | Examples of valid input documents |
---|---|
|
|
6. Constant or default values
Sometimes it is helpful to provide a constant or default value for an input field.
Using the "default"
keyword provides an initial but changeable value for the field
while "const"
provides a fixed value that cannot be changed and will produce an error
if a different value is submitted by the user.
The Globus Web App recognizes a "default"
property for input fields, and will use
that value as the default value for the input field in the guided input form but still
allow the value to be changed. The "const"
property will be used as the default value
and will not allow the value to be changed.
"default"
keyword{
"properties": {
"some_id": {
"type": "string",
"default": "1111-2222-3333-4444-5555"
}
}
}
"const"
keyword{
"properties": {
"important_number": {
"type": "number",
"const": 3.14
}
}
}
Both "default"
and "const"
can also be used with all of the Globus formats as well.
"const"
with "globus-collection"
format{
"type": "object",
"required": [
"source"
],
"properties": {
"source": {
"type": "object",
"format": "globus-collection",
"title": "Source collection and path",
"required": [
"id",
"path"
],
"properties": {
"id": {
"type": "string",
"format": "uuid"
},
"path": {
"type": "string"
}
},
"const": {
"id": "ec160529-be4e-47bf-8c46-899e96e14909",
"path": "/"
}
"additionalProperties": false
}
}
}
"const"
with "globus-principal"
format{
"type": "object",
"format": "globus-principal",
"const": {
"id": "1d611a6d-9a22-4de5-b855-ba793df9b309",
"urn": "urn:globus:auth:identity:1d621a6d-9a22-4de5-b855-ba793df4b309",
"type": "identity"
}
}
7. Providing hints to the guided input form
The Globus Web App uses input schemas to generate a guided input form.
As seen previously, flow authors can use the "title"
and "description"
properties
to improve that user interface for users.
There are other ways that flow authors can improve the interface.
7.1. The "globus-collection"
format
When writing a flow that interacts with the Globus Transfer service,
it is common to accept a Globus collection and/or a path as inputs to the flow.
The Globus Web App recognizes a unique "object"
format, "globus-collection"
,
which it uses to generate a user interface that supports searching for Globus collections
and browsing for paths on a selected collection.
"globus-collection"
{
"type": "object",
"required": [
"source"
],
"properties": {
"source": {
"type": "object",
"format": "globus-collection",
"title": "Source collection and path",
"required": [
"id",
"path"
],
"properties": {
"id": {
"type": "string",
"format": "uuid"
},
"path": {
"type": "string"
}
},
"additionalProperties": false
}
}
}
"globus-collection"
-formatted objectThe Globus Web App only recognizes the "globus-collection"
format for "object"
types,
and the nested properties must be named "id"
and "path"
.
One or both of the "id"
and "path"
properties must be included.
{
"source": {
"id": "ec160529-be4e-47bf-8c46-899e96e14909",
"path": "/~/"
}
}
7.2. The "globus-principal"
format
Many flows will require information about a particular identity or group in order
to accomplish their tasks. For example, a flow that wishes to grant a user access
to a particular collection will need that user’s identity ID. The Globus Web App
recognizes a unique "object"
or "array"
type combined with a format value of
"globus-principal"
. This format will generate a particular user interface
so that searching for and selecting these principal values as part
of the input to a flow is much easier.
Example selecting a single principal value
"globus-principal"
to select a single principal using the "object"
type{
"title": "Select a Globus Identity or Group",
"type": "object",
"required": [
"principal"
],
"properties": {
"principal": {
"type": "object",
"title": "Principal",
"format": "globus-principal"
}
},
"additionalProperties": false
}
"object"
type{
"principal": {
"id": "11111111-7f6d-11e9-9cda-0a06afd4a22e",
"type": "identity",
"urn": "urn:globus:auth:identity:e7c0c8e4-7f6d-11e9-9cda-0a06afd4a22e"
}
}
Example selecting multiple principal values
"globus-principal"
to select multiple principals using the "array"
type{
"title": "Select Globus Identities and Groups",
"type": "object",
"required": [
"principals"
],
"properties": {
"principals": {
"type": "array",
"title": "Principals",
"format": "globus-principal"
}
},
"additionalProperties": false
}
"array"
type{
"principals": [
{
"id": "11111111-7f6d-11e9-9cda-0a06afd4a22e",
"urn": "urn:globus:auth:identity:11111111-9a22-4de5-b855-ba793df9b309",
"type": "identity"
},
{
"id": "22222222-7f6d-11e9-9cda-0a06afd4a22e",
"urn": "urn:globus:groups:id:22222222-7f6d-11e9-9cda-0a06afd4a22e",
"type": "group"
}
]
}
"globus-principal"
-format7.3. Ordering input fields in the guided input form
Sometimes it’s helpful to order the input fields in the guided input form.
For example, it is common for a "source" field to appear before a "destination" field.
The Globus Web App recognizes a "propertyOrder"
property for "object"
types,
which allows flow authors to make the guided input form more intuitive for users.
The "propertyOrder"
is a list of properties in the order they should appear
in the guided input form.
"propertyOrder"
{
"type": "object",
"propertyOrder": [
"3",
"2",
"1"
],
"properties": {
"1": {
"type": "string"
},
"2": {
"type": "string"
},
"3": {
"type": "string"
}
}
}
8. Next steps
Please see our How to Run a Flow guide for a description of how to run your flow using the Globus Web App.