Skip to content

Markdown

SchemaOperation

A SchemaOperation is one schema operation offered to a model as a tool: describe_schema, preview_schema_changes, or apply_schema_changes. Get one from App.operation(). apply_schema_changes only runs with the confirmation preview_schema_changes returned for the same changes, while the schema is as it was.

The examples below use plan, made as shown here. Job Tasks has Title, Status, Hours, Due Date, Code, which is unique, and Attachment. It starts with three records, and each example starts from those again. A live test runs every example with both clients and checks its output.

from pyquickbase import Quickbase

with Quickbase(
    realm="acme", token="your_user_token"
) as qb:
    app = qb.app("bq1234567")
    plan = app.operation("preview_schema_changes")
from pyquickbase import AsyncQuickbase

async with AsyncQuickbase(
    realm="acme", token="your_user_token"
) as qb:
    app = qb.app("bq1234567")
    plan = await app.operation("preview_schema_changes")

Describe it to a model

For the full picture, see Using pyquickbase from an AI agent.

The arguments' JSON Schema

The JSON Schema of the arguments a model may send, for a tool's input.

It's self-contained, with no $ref, and a new dictionary each time, so you can add to it.

schema: dict[str, Any]

Example

changes = plan.schema["properties"]["changes"]
kinds = [
    item["properties"]["action"]["const"]
    for item in changes["items"]["oneOf"]
]
print(kinds[:3])
changes = plan.schema["properties"]["changes"]
kinds = [
    item["properties"]["action"]["const"]
    for item in changes["items"]["oneOf"]
]
print(kinds[:3])

Output

['create_table', 'update_table', 'delete_table']

The operation's name

What the operation does, such as preview_schema_changes.

name: SchemaOperationName

Example

print(plan.name)
print(plan.name)

Output

preview_schema_changes

Run it

For the full picture, see Using pyquickbase from an AI agent.

Run a schema operation

Check a model's arguments, and run the operation.

Parameters

  • arguments Mapping[str, Any], required
    The arguments from the model's tool call.

Returns Any

For describe_schema, a list of TableSchema. For preview_schema_changes, a SchemaPlan, whose confirmation apply_schema_changes needs, unless the plan has blockers or changes nothing. For apply_schema_changes, a SchemaChangeResult. tool_result takes each.

Raises

  • InvalidValueError: An argument can't be used. Nothing was sent.
  • QueryError: apply_schema_changes has no confirmation, or one that doesn't match these changes and the schema as it is now. Nothing was changed.
  • SchemaChangeError: A change failed while applying. Its result says which were made.
run(arguments: Mapping[str, Any]) -> Any

Example

from pyquickbase import tool_result

change = {
    "action": "create_field",
    "table": "Job Tasks",
    "label": "Crew",
    "type": "text",
}
result = tool_result(plan.run({"changes": [change]}))
print(result["changes"][0]["summary"])
print("confirmation" in result)
from pyquickbase import tool_result

change = {
    "action": "create_field",
    "table": "Job Tasks",
    "label": "Crew",
    "type": "text",
}
result = tool_result(await plan.run({"changes": [change]}))
print(result["changes"][0]["summary"])
print("confirmation" in result)

Output

Add field "Crew" (text) to Job Tasks.
True