# Best Practices

### Best Practices

#### 1. Prompt Engineering

**Clear and Specific Instructions**

```json
// ❌ Bad
{
    "prompt": "Get product information"
}

// ✅ Good
{
    "prompt": "Extract the product's name, current price, original price (if on sale), available sizes, and color options. For prices, include the currency symbol."
}
```

**Define Expected Format**

```json
// ❌ Bad
{
    "prompt": "What are the key features of this product?"
}

// ✅ Good
{
    "prompt": "List the product's key features as an array of strings, with each feature being a concise single sentence."
}
```

**Include Validation Rules**

```json
// ❌ Bad
{
    "prompt": "Get the product price and rating"
}

// ✅ Good
{
    "prompt": "Extract the product price (as a number without currency symbol) and rating (must be between 0 and 5, with one decimal place)"
}
```

#### 2. Data Structuring

**Clear Hierarchy**

```json
// ❌ Bad
{
    "prompt": "Get all prices from the page"
}

// ✅ Good
{
    "prompt": "Extract pricing information in this structure: base_price (number), additional_options (array of objects with name and price), discounts (array of objects with description and amount)"
}
```

**Handle Missing Data**

```json
// ❌ Bad
{
    "prompt": "Get the author's name and bio"
}

// ✅ Good
{
    "prompt": "Extract the author's details with these rules: name (string, use 'Anonymous' if not found), bio (string, use null if not present), role (string, use 'Contributor' if not specified)"
}
```

#### 3. Performance Optimization

**Focused Extraction**

```json
// ❌ Bad
{
    "prompt": "Get everything from the page"
}

// ✅ Good
{
    "prompt": "Extract only the technical specifications table, converting it to a JSON object with spec_name as keys and spec_value as values"
}
```

**Batch Processing**

```json
// ❌ Bad: Multiple separate requests
{
    "prompt": "Get product prices"
}
{
    "prompt": "Get product features"
}

// ✅ Good: Single comprehensive request
{
    "prompt": "Extract all product information in a single structured response: prices (object), features (array), specifications (object)"
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yetanotherapi.com/llm-web-scraper/best-practices.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
