Functions
parse_input()
Extract a JSON object from a text string, with optional dataclass validation.| Parameter | Type | Required | Description |
|---|---|---|---|
prompt | str | Yes | The enriched prompt text from Friday |
schema | type | None | No | Dataclass type for typed extraction |
dict or dataclass instance
Raises:
ValueError- No valid JSON object found in promptTypeError- Schema is not a dataclassValueError- JSON doesn’t match dataclass (missing required fields)
parse_operation()
Extract an operation config using a discriminator field.| Parameter | Type | Required | Description |
|---|---|---|---|
prompt | str | Yes | The enriched prompt text |
schemas | dict[str, type[T]] | Yes | Map of operation name to dataclass type |
ValueError - No valid operation config found
Example:
Extraction Strategy
Both functions search in this order:- Balanced-brace JSON objects - Hand-rolled scanner handles arbitrary nesting
- Code-fenced JSON blocks - Extracts from
```json ... ``` - Full prompt - Attempts to parse entire prompt as JSON
parse_operation(), only JSON objects containing an "operation" field are considered, and the discriminator value selects the schema.
JSON in Markdown
Input may look like:parse_input() and parse_operation() extract the JSON block correctly.
Dataclass Validation
When using a schema:- Only fields defined in the dataclass are extracted (unknown keys filtered)
- Missing required fields raise
ValueErrorwith clear message - Type hints are not enforced at runtime (Python limitation)
Error Messages
Clear errors for debugging:Real Example: Jira Agent
When to Use
| Function | Use When |
|---|---|
parse_input(prompt) | Single configuration, flexible parsing, no operation types |
parse_input(prompt, Schema) | Single configuration, want typed fields |
parse_operation(prompt, schemas) | Multiple operations, discriminated by "operation" field |
Implementation Details
The balanced-brace scanner:- Handles arbitrary nesting depth (recursive objects/arrays)
- Tracks string boundaries and escape sequences
- Avoids miscounting braces inside string literals
- Returns all valid JSON objects found, tries each in order
See Also
How to Handle Structured Input
Task-oriented guide

