- Ergonomic Rig Functions
- AI-Optimized Functions
- LLM-Friendly Functions
- Traditional API
- Types and Structs
- Error Types
These functions are specifically designed for Rig framework integration and AI agents. They are all async and provide clean, simple responses.
pub async fn rig_is_valid(url: &str) -> boolUltra-simple boolean validation check.
Example:
if rig_is_valid("https://linkedin.com/in/johndoe").await {
println!("Valid profile!");
}pub async fn rig_validate_text(url: &str) -> StringReturns a one-line human-readable response perfect for chat interfaces.
Example responses:
"✅ Valid profile @johndoe (95% confidence)""❌ Invalid LinkedIn URL - Search for a different LinkedIn profile URL"
pub async fn rig_validate_json(url: &str) -> StringReturns clean JSON output optimized for tool responses.
Example:
impl Tool for LinkedInValidator {
async fn call(&self, args: Args) -> Result<String, Error> {
Ok(rig_validate_json(&args.url).await)
}
}pub async fn rig_validate(url: &str) -> RigValidationResultReturns structured validation data with all details.
Returns: RigValidationResult
These functions provide rich structured data for AI decision-making.
pub fn ai_validate(url: &str) -> AIValidationResultSynchronous validation returning comprehensive structured data.
Returns: AIValidationResult
pub async fn ai_validate_async(url: &str) -> AIValidationResultAsync version of ai_validate.
pub fn ai_validate_json(url: &str) -> StringReturns AI validation result as JSON string.
pub async fn ai_validate_json_async(url: &str) -> StringAsync version of ai_validate_json.
These functions return verbose text reports designed for LLM consumption.
pub fn validate_for_llm(url: &str) -> StringReturns extremely verbose validation report with:
- Timestamps
- Severity levels
- Detailed explanations
- 5-7 suggested actions
- Recommended next steps
pub async fn validate_for_llm_async(url: &str) -> StringAsync version of validate_for_llm.
pub struct LinkedInValidator { /* private fields */ }Main validator struct for traditional usage.
pub fn new() -> Result<Self, LinkedInUrlError>Creates a new validator with default settings.
pub fn new_with_user_agent(user_agent: &str) -> Result<Self, LinkedInUrlError>Creates a validator with custom user agent.
pub fn is_valid_linkedin_profile_url(&self, url: &str) -> Result<bool, LinkedInUrlError>Validates a LinkedIn profile URL with network check.
pub fn is_valid_linkedin_profile_format(url: &str) -> boolChecks URL format without network calls.
pub async fn validate_linkedin_url_async(url: &str) -> Result<bool, LinkedInUrlError>Async validation with network check.
pub struct RigValidationResult {
pub valid: bool, // Simple pass/fail
pub username: Option<String>, // LinkedIn username if found
pub confidence: u8, // 0-100 percentage
pub status: String, // Human-readable status
pub action: String, // Suggested action for AI
}pub struct AIValidationResult {
pub is_valid: bool,
pub confidence: f32, // 0.0 to 1.0
pub decision: AIDecision,
pub username: Option<String>,
pub reason: String,
pub metadata: ValidationMetadata,
}pub enum AIDecision {
Accept, // Definitely use this URL
Retry, // Temporary issue, try again
Reject, // Invalid URL, search for another
}pub struct ValidationMetadata {
pub url_format_valid: bool,
pub domain_verified: bool,
pub profile_pattern_matched: bool,
pub http_status: Option<u16>,
pub error_type: Option<String>,
pub timestamp: String,
}pub enum LinkedInUrlError {
InvalidUrl(String),
NotLinkedInUrl,
NotProfileUrl,
NetworkError(reqwest::Error),
ProfileNotFound,
AuthenticationRequired,
}| Error | Description |
|---|---|
InvalidUrl |
The URL format is invalid |
NotLinkedInUrl |
Not a LinkedIn domain |
NotProfileUrl |
LinkedIn URL but not a profile |
NetworkError |
Network request failed |
ProfileNotFound |
Profile doesn't exist (404) |
AuthenticationRequired |
LinkedIn requires auth (999) |
impl Tool for LinkedInValidator {
async fn call(&self, args: Args) -> Result<String, Error> {
// Use ergonomic helper
Ok(rig_validate_json(&args.url).await)
}
}let result = ai_validate_async(url).await;
match result.decision {
AIDecision::Accept => use_profile(result.username),
AIDecision::Retry => schedule_retry(),
AIDecision::Reject => search_for_another(),
}if is_valid_linkedin_profile_format(url) {
// Format is correct, proceed with validation
}