Skip to content

Response Validation & Sanitization #12

@mheadd

Description

@mheadd

Summary

Clean Data Before Returning to LLM

// In internal/api/nps.go
func (c *NPSClient) SearchParks(ctx context.Context, opts SearchParksOptions) ([]models.Park, error) {
    parks, err := c.fetchParks(ctx, opts)
    if err != nil {
        return nil, err
    }
    
    // Sanitize for LLM consumption
    for i := range parks {
        parks[i] = sanitizePark(parks[i])
    }
    
    return parks, nil
}

func sanitizePark(park models.Park) models.Park {
    // Remove HTML tags from descriptions
    park.Description = stripHTML(park.Description)
    
    // Normalize whitespace
    park.Description = normalizeWhitespace(park.Description)
    
    // Truncate overly long fields
    if len(park.Description) > 2000 {
        park.Description = park.Description[:1997] + "..."
    }
    
    // Remove empty/null fields that add noise
    park = removeEmptyFields(park)
    
    return park
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions