A LangGraph agent that analyzes C2PA (Coalition for Content Provenance and Authenticity) and IPTC (International Press Telecommunications Council) metadata in images to determine if they are AI-generated.
- C2PA Metadata Analysis: Uses the official c2pa-python library to read and validate C2PA manifests, extracting:
- C2PA manifest assertions and claims
- Ingredients (components used to create the asset)
- Claim generator information
- Full manifest JSON for comprehensive analysis
- IPTC Metadata Analysis: Checks for IPTC (International Press Telecommunications Council) metadata, including:
- Digital Source Type fields (trainedAlgorithmicMedia, algorithmicMedia, compositeSynthetic)
- Provider fields (e.g., "Made with Google AI")
- Other IPTC fields that may indicate AI generation
- AI Generation Detection: Identifies AI-generated content based on metadata indicators from both C2PA and IPTC
- Multimodal Visual Analysis: GPT-4 Vision integration for visual AI detection
- Type-Safe Architecture: Pydantic models ensure data integrity and validation throughout the pipeline
- LangGraph Agent: Uses LangGraph to create an intelligent agent workflow with sequential node processing
- Detailed Explanations: Provides clear explanations of why an image is or isn't AI-generated with confidence levels
- Python 3.12+
- uv package manager
- OpenAI API key (for the LLM)
- Install dependencies using
uv:
uv sync- Set your OpenAI API key:
export OPENAI_API_KEY="your-api-key-here"Or set it in the notebook directly.
- Start Jupyter Notebook:
uv run jupyter notebook-
Open
fake_news_identifier.ipynb -
Run all cells to set up the agent
-
Use the agent to analyze an image:
result = analyze_image(
"Is this image AI-generated? Please check the metadata and explain.",
"path/to/your/image.jpg"
)
print(result)-
Metadata Checker Tool: The
check_image_metadatatool examines:- C2PA Metadata (using official c2pa-python library):
- Reads and validates C2PA manifests from images
- Extracts manifest assertions, claims, and ingredients
- Analyzes claim generator information
- Checks for AI generation indicators in C2PA manifest data
- IPTC Metadata: IPTC fields including:
- Digital Source Type (checks for trainedAlgorithmicMedia, algorithmicMedia, compositeSynthetic)
- Provider field (checks for AI service providers like "Made with Google AI", "DALL-E", etc.)
- Other IPTC fields that may contain AI generation indicators
- AI Generation Indicators: Looks for common AI service markers (DALL-E, Midjourney, Stable Diffusion, ChatGPT, Gemini, etc.)
- C2PA Metadata (using official c2pa-python library):
-
LangGraph Workflow: The agent follows a sequential pipeline:
- Metadata Analysis Node: Extracts and analyzes C2PA and IPTC metadata
- Visual Analysis Node: Uses GPT-4 Vision to analyze visual characteristics
- Synthesis Node: Combines metadata and visual evidence into a final verdict
- Agent Node: Generates a detailed explanation based on all findings
-
Type-Safe Processing: Throughout the pipeline:
- Pydantic models validate all data structures
- TypedDict ensures state consistency
- Type annotations provide IDE support and catch errors early
-
Analysis Results: The workflow returns:
- Whether C2PA and/or IPTC metadata is present
- C2PA manifest details (assertions, ingredients, claim generator)
- Specific IPTC fields found (Provider, DigitalSourceFileType, etc.)
- AI generation indicators found in both C2PA and IPTC metadata
- Confidence level (high/medium/low)
- Detailed metadata information from all sources
- C2PA and IPTC metadata can be stripped during image processing or sharing
- Absence of metadata doesn't definitively mean an image isn't AI-generated
- Some AI generators may not include C2PA or IPTC metadata
- The tool relies on metadata presence; it cannot detect AI generation through visual analysis alone
- IPTC field names may vary between different image formats and metadata implementations
c2pa-python: Official C2PA library for reading and validating C2PA manifests (GitHub)pydantic: Data validation and type safety using Python type annotationslanggraph: For building the agent workflow with state managementlangchain: Core LangChain functionalitylangchain-openai: OpenAI integration (including GPT-4 Vision)pillow: Image processingpiexif: EXIF data parsingiptcinfo3: IPTC metadata parsingjupyter: Notebook environmentpython-dotenv: Environment variable management
C2PA is a technical standard that enables publishers, creators, and consumers to trace the origin and evolution of digital media. Key learnings:
- Manifest Structure: C2PA embeds manifests in media files using JUMBF (JPEG Universal Metadata Box Format) containers
- Provenance Chain: C2PA maintains a chain of custody showing how content was created and modified
- Assertions: Manifests contain assertions that describe actions taken on the content (e.g., "generated by AI", "edited", "cropped")
- Ingredients: C2PA tracks "ingredients" - source files or assets used to create the final media
- Claim Generator: Each manifest includes information about the tool/service that created it
- Validation: The official c2pa-python library can read and validate manifests, ensuring authenticity
Why C2PA Matters: As AI-generated content becomes more prevalent, C2PA provides a standardized way to verify content provenance. However, metadata can be stripped during processing, so it's not foolproof.
IPTC (International Press Telecommunications Council) metadata provides structured information about digital images:
- Digital Source Type: IPTC defines specific codes for AI-generated content:
trainedAlgorithmicMedia: Content generated using models trained on sampled contentalgorithmicMedia: Content created purely algorithmically without training datacompositeSynthetic: Composite images containing synthetic elements
- Provider Field: Often contains information about the AI service used (e.g., "Made with Google AI", "DALL-E")
- Field Variations: IPTC field names can vary between implementations, requiring flexible parsing
Detection Strategy: By checking IPTC's DigitalSourceFileType field for trainedAlgorithmicMedia or examining the Provider field for AI service indicators, we can identify AI-generated content with high confidence.
Through this project, we've explored multiple detection approaches:
-
Metadata-Based Detection (Primary Method):
- C2PA Manifests: Check for C2PA assertions indicating AI generation
- IPTC Fields: Look for
trainedAlgorithmicMediaor AI provider names - EXIF Data: Some tools embed AI generation info in EXIF tags
- Advantages: High accuracy when metadata is present
- Limitations: Metadata can be stripped or may not exist
-
Visual Analysis (Complementary Method):
- Multimodal AI Models: Use GPT-4 Vision to analyze visual characteristics
- Artifact Detection: Look for common AI generation artifacts (inconsistent lighting, strange textures, etc.)
- Style Patterns: Identify stylistic patterns common to specific AI models
- Advantages: Works even when metadata is missing
- Limitations: Less reliable, can produce false positives/negatives
-
Hybrid Approach (Most Effective):
- Combine metadata analysis with visual inspection
- High confidence when both methods agree
- Medium confidence when one method strongly indicates
- Low confidence when evidence is conflicting or insufficient
This project demonstrates modern Python AI agent development using:
LangGraph:
- State Management: TypedDict-based state for type-safe data flow
- Node-Based Workflow: Sequential pipeline:
analyze_metadata → analyze_visual → synthesize → agent - Graph Compilation: Compiles to an executable workflow with checkpointing
- Memory: Uses MemorySaver for conversation state persistence
Pydantic Models:
- Type Safety: All data structures validated at runtime
- Documentation: Field descriptions serve as inline documentation
- Error Handling: Automatic validation catches type mismatches early
- Structured Output: Ensures consistent data formats throughout the pipeline
Architecture Benefits:
- Separation of Concerns: Each node has a single responsibility
- Type Safety: Pydantic models catch errors before runtime
- Testability: Each node can be tested independently
- Extensibility: Easy to add new analysis methods or nodes
- Maintainability: Clear structure makes code easy to understand and modify
Key Design Decisions:
- Multimodal as Node, Not Tool: Visual analysis is a graph node for better type safety and workflow control
- Pydantic Throughout: All intermediate results use Pydantic models for validation
- Sequential Pipeline: Simple linear flow ensures data dependencies are clear
- Synthesis Node: Combines multiple evidence sources into a final verdict
This implementation provides comprehensive C2PA and IPTC metadata checking using:
- Official C2PA Library: Uses c2pa-python for authoritative C2PA manifest reading and validation
- IPTC Support: Comprehensive IPTC metadata parsing with field name variation handling
- Type-Safe Architecture: Pydantic models ensure data integrity throughout the pipeline
- Multimodal Analysis: GPT-4 Vision integration for visual AI detection
The current implementation has limitations in detecting AI-generated images that:
- Don't include C2PA or IPTC metadata (e.g., some Gemini-generated images)
- Have metadata stripped during processing or sharing
- Are generated by services that don't yet implement provenance standards
Problem: Current visual analysis using GPT-4 Vision is general-purpose and may miss subtle AI generation artifacts.
Solution: Train specialized CNN or Vision Transformer models specifically for AI detection:
- Dataset: Collect large datasets of:
- AI-generated images from various models (DALL-E, Midjourney, Stable Diffusion, Gemini, etc.)
- Authentic photographs for comparison
- Mixed datasets with various image types and styles
- Model Architecture:
- Use pre-trained models (ResNet, EfficientNet, Vision Transformer) as feature extractors
- Fine-tune on AI vs. authentic image classification
- Consider ensemble methods combining multiple models
- Training Strategy:
- Data augmentation to handle various image sizes, formats, and qualities
- Focus on detecting specific artifacts (see "Dead Pixel Detection" below)
- Multi-class classification to identify which AI model generated the image
- Integration: Add as a new graph node in the LangGraph workflow
Benefits:
- Higher accuracy for images without metadata
- Can detect subtle patterns humans might miss
- Can identify specific AI models used
Current State: Not all AI image generators include C2PA metadata by default.
Future Outlook:
- Industry Adoption: As major players (OpenAI, Google, Adobe, etc.) adopt C2PA standards, more AI-generated images will include provenance metadata
- Regulatory Pressure: Potential regulations may require AI-generated content to include provenance metadata
- User Demand: Growing awareness may drive demand for verifiable content
Action Items:
- Monitor C2PA adoption rates across major AI services
- Update detection logic as new C2PA assertion types emerge
- Add support for C2PA extensions and custom assertions
Expected Impact:
- Significantly improved detection rates for images from C2PA-compliant services
- More reliable provenance chains for content verification
Problem: AI-generated images often contain subtle artifacts that can be detected programmatically.
Solution: Implement specialized detection algorithms for common AI generation artifacts:
Dead Pixel Detection:
- Pattern Analysis: Look for repeating patterns or anomalies in pixel values
- Frequency Domain Analysis: Use FFT to detect unusual frequency patterns common in AI-generated images
- Statistical Anomalies: Detect regions with statistically unusual pixel distributions
- Grid Artifacts: Identify grid-like patterns that some AI models produce
Other Artifact Detection:
- Inconsistent Lighting: Detect lighting inconsistencies that are common in AI images
- Texture Anomalies: Identify areas where textures don't match expected patterns
- Edge Artifacts: Detect unusual edge patterns or halos around objects
- Color Gradients: Analyze color gradients for unnatural transitions
- Depth Inconsistencies: Detect perspective or depth inconsistencies
Implementation Approach:
- Use computer vision libraries (OpenCV, scikit-image) for image analysis
- Implement statistical tests for artifact detection
- Create a scoring system that combines multiple artifact indicators
- Add as a new analysis node:
analyze_artifacts_node()
Benefits:
- Works even when metadata is completely absent
- Can detect AI generation with high confidence when multiple artifacts are present
- Complements metadata-based detection
Metadata Expansion:
- XMP Metadata: Add support for XMP (Extensible Metadata Platform) which some tools use
- EXIF Analysis: Enhanced EXIF parsing to detect AI generation markers
- Watermark Detection: Detect invisible watermarks some AI services embed
Visual Analysis Improvements:
- Multi-Model Ensemble: Use multiple vision models (GPT-4 Vision, Claude Vision, etc.) and combine results
- Specialized Prompts: Develop domain-specific prompts for different image types
- Confidence Calibration: Better calibration of visual analysis confidence scores
Workflow Enhancements:
- Parallel Processing: Run metadata and visual analysis in parallel for faster results
- Conditional Routing: Skip visual analysis if metadata provides high-confidence result
- Iterative Refinement: Allow the agent to request additional analysis if confidence is low
Performance & Scalability:
- Caching: Cache analysis results for repeated queries
- Batch Processing: Process multiple images simultaneously
- Model Optimization: Use quantized or smaller models for faster inference
User Experience:
- Visualization: Show detected artifacts highlighted on the image
- Detailed Reports: Generate comprehensive PDF reports with evidence
- API Endpoint: Expose as a REST API for integration with other systems
Based on current limitations (e.g., Gemini images not being detected), recommended priority order:
- High Priority: Dead pixel and artifact detection (immediate impact, no external dependencies)
- Medium Priority: CNN/Transformer model training (requires dataset collection and training infrastructure)
- Long-term: Monitor C2PA adoption (depends on industry adoption, but will improve naturally over time)
- Fingerprinting Techniques: Research into model-specific fingerprints that can identify which AI model generated an image
- Adversarial Detection: Methods to detect images that have been adversarially modified to evade detection
- Temporal Analysis: Track detection patterns over time as AI models evolve
- Cross-Modal Detection: Combine image analysis with text analysis when images are part of larger content
For production use, consider:
- Adding support for XMP metadata parsing (some IPTC data may be stored in XMP)
- Implementing additional visual detection methods (e.g., artifact-specific models)
- Adding support for more image formats and metadata standards
- Handling edge cases where IPTC field names may vary between implementations
- Adding C2PA manifest signing capabilities for creating provenance metadata
- Implementing caching for repeated analyses
- Adding batch processing capabilities for multiple images