# Parameter Extraction — Dify Workflow Basics

Source: https://www.skillbyai.com/en/dify-workflows/c-extract

> Turn free text into fields.

## Model extracts, code validates

The **parameter extractor** node uses an LLM to pull defined fields (order ID, issue, amount) out of free text and returns them as variables. Define each parameter with a type and a clear description. Extraction can still fail (missing fields, wrong types, text instead of JSON), so validate the result before use, for example with a code node, and route invalid results to a clarification question or a human. Dify's node names, menus and options change between versions; check the current Dify documentation.

## Validating extracted fields, run

I ran this with plain Python 3 (scikit-learn 1.9.1 where imported). It models or tests one piece of a Dify app locally; Dify itself was not running. Four example extraction outputs are checked against a schema: a complete record passes, a missing amount is caught, a numeric order_id and a text amount are caught, and plain prose is rejected as not JSON.

```python
import json
schema = {"order_id": str, "issue": str, "amount": (int, float)}
def validate(raw):
    try:
        data = json.loads(raw)
    except json.JSONDecodeError:
        return "not JSON"
    problems = [k for k, t in schema.items() if k not in data or not isinstance(data[k], t)]
    return "ok" if not problems else f"invalid fields: {problems}"
for raw in ['{"order_id": "A1042", "issue": "damaged", "amount": 1299}',
            '{"order_id": "A1042", "issue": "damaged"}',
            '{"order_id": 1042, "issue": "late", "amount": "1299"}',
            'The order id is A1042']:
    print(f"{validate(raw):<34} <- {raw}")
```

Output:

```
ok                                 <- {"order_id": "A1042", "issue": "damaged", "amount": 1299}
invalid fields: ['amount']         <- {"order_id": "A1042", "issue": "damaged"}
invalid fields: ['order_id', 'amount'] <- {"order_id": 1042, "issue": "late", "amount": "1299"}
not JSON                           <- The order id is A1042
```

## Ask for missing fields

In chatflows, when a required parameter is missing, ask the user for it instead of guessing.

**Quiz:** Why validate parameter extractor output?

- [x] The model can omit fields or return wrong types
- [ ] Extraction is always perfect
- [ ] Validation trains the model
- [ ] It reduces the number of nodes

*Answer:* The model can omit fields or return wrong types. Trust, but check.
