# Brazil2026ElectionFilter: How X-Algorithm Implements Brazil's 2026 Election Content Moderation

> Discover how the Brazil2026ElectionFilter safeguards Brazil's 2026 elections by moderating content and ensuring compliance with electoral regulations. Learn its function and impact.

- Repository: [SpaceXAI Org/x-algorithm](https://github.com/xai-org/x-algorithm)
- Tags: how-to-guide
- Published: 2026-09-10

---

**The `Brazil2026ElectionFilter` removes posts authored, retweeted, quoted, or replied to by accounts reported to the Brazilian Electoral Court for the 2026 election from recommendation results, unless the viewer follows those accounts, ensuring compliance with Electoral Resolution No. 23.610.**

The `Brazil2026ElectionFilter` serves as a critical compliance mechanism within the X-Algorithm recommendation pipeline. Located in the `xai-org/x-algorithm` repository, this Rust-based component operates within the home-mixer crate to filter candidate posts during feed generation. It balances Brazilian legal requirements with user autonomy by preserving content from followed accounts while removing potentially problematic electoral content from algorithmic recommendations.

## Purpose and Legal Compliance

The filter enforces **Electoral Resolution No. 23.610, Art. 28 §1º-A**, which mandates the removal of specific accounts from algorithmic promotion during electoral periods. This regulation targets accounts that have been formally reported to the Brazilian Electoral Court regarding the 2026 election cycle.

Unlike blanket censorship, the implementation respects user agency through the **follower exception rule**. The filter only removes content when the viewer does not already follow the author, preserving the ability of users to see content from accounts they have explicitly chosen to follow. This architectural decision reflects the nuanced requirements of Brazilian electoral law while maintaining user choice.

## How Brazil2026ElectionFilter Works

The filter implements the generic `Filter<ScoredPostsQuery, PostCandidate>` trait, allowing seamless integration into the candidate processing pipeline. The implementation follows a four-step validation process:

### Static Prohibited User ID Set

At the core of the filter lies `BRAZIL_2026_ELECTION_USER_IDS`, a `LazyLock<FxHashSet<u64>>` containing approximately 2,500 user IDs. This static set, defined in [`home-mixer/filters/brazil_2026_election_filter.rs`](https://github.com/xai-org/x-algorithm/blob/main/home-mixer/filters/brazil_2026_election_filter.rs), derives from the open data set of 2026 election candidates. The `FxHashSet` provides O(1) lookup performance critical for high-throughput recommendation processing.

### Author Exclusion Logic

The `is_excluded_author(user_id, followed_user_ids)` function determines whether a specific author should be filtered. This function returns `true` only when two conditions coincide:

- The `user_id` exists within `BRAZIL_2026_ELECTION_USER_IDS`
- The user ID is **not** present in the viewer's `followed_user_ids` vector

This logic enforces the legal requirement while implementing the follow-relationship exemption.

### Multi-Relationship Candidate Evaluation

The `should_remove(candidate, followed_user_ids)` method performs comprehensive relationship checking across four potential vectors of content propagation:

1. **Direct authorship** – The candidate's `author_id` is excluded
2. **Retweet origin** – The original author of a retweeted post is excluded  
3. **Quote attribution** – The author of quoted content is excluded
4. **Reply ancestry** – Any ancestor user in a reply thread is excluded

If any of these conditions evaluates to true, the candidate is marked for removal from the recommendation set.

### Pipeline Integration and Partitioning

Within the `filter` method implementation, the system extracts the viewer's `followed_user_ids` from the `ScoredPostsQuery` context. The candidate vector undergoes partitioning into `kept` and `removed` collections based on the `should_remove` evaluation. The method returns a `FilterResult` structure containing both sets, allowing the pipeline to track moderation decisions for potential logging or analysis.

## Code Implementation and Architecture

### Direct Filter Usage

When working with the filter outside the standard pipeline, implementers interact with the `Filter` trait directly:

```rust
use home_mixer::filters::brazil_2026_election_filter::Brazil2026ElectionFilter;
use xai_candidate_pipeline::filter::{Filter, FilterResult};
use home_mixer::models::{candidate::PostCandidate, query::ScoredPostsQuery};

// Construct query with viewer's follow relationships
let query = ScoredPostsQuery {
    user_features: UserFeatures {
        followed_user_ids: vec![12345, 67890],
        ..Default::default()
    },
    ..Default::default()
};

// Create candidate batch containing mixed authors
let candidates = vec![
    PostCandidate { tweet_id: 1, author_id: 1, ..Default::default() },          // Permitted
    PostCandidate { tweet_id: 2, author_id: 14160928, ..Default::default() }, // Blocked ID
];

let filter = Brazil2026ElectionFilter;
let result: FilterResult<PostCandidate> = filter.filter(&query, candidates);

// Verify filtering behavior
assert_eq!(result.kept.len(), 1);
assert_eq!(result.removed[0].author_id, 14160928);

```

### Pipeline Registration

The filter integrates into the Phoenix candidate pipeline through explicit registration in [`phoenix_candidate_pipeline.rs`](https://github.com/xai-org/x-algorithm/blob/main/phoenix_candidate_pipeline.rs):

```rust
use crate::filters::brazil_2026_election_filter::Brazil2026ElectionFilter;

let filters: Vec<Box<dyn Filter<ScoredPostsQuery, PostCandidate>>> = vec![
    // Preceding filters...
    Box::new(Brazil2026ElectionFilter),
    // Subsequent filters...
];

```

During request processing, the pipeline invokes each filter's `filter` method sequentially. The Brazil 2026 filter executes early in the chain, ensuring prohibited content never reaches downstream ranking or feature extraction stages.

## Key Source Files and Data Structures

Understanding the filter requires familiarity with these specific files in the `xai-org/x-algorithm` repository:

- **[`home-mixer/filters/brazil_2026_election_filter.rs`](https://github.com/xai-org/x-algorithm/blob/main/home-mixer/filters/brazil_2026_election_filter.rs)** – Contains the `Brazil2026ElectionFilter` struct, static ID set, trait implementation, and comprehensive unit tests
- **[`home-mixer/candidate_pipeline/phoenix_candidate_pipeline.rs`](https://github.com/xai-org/x-algorithm/blob/main/home-mixer/candidate_pipeline/phoenix_candidate_pipeline.rs)** – Registers the filter within the candidate processing pipeline at lines 38-41
- **[`home-mixer/models/candidate.rs`](https://github.com/xai-org/x-algorithm/blob/main/home-mixer/models/candidate.rs)** – Defines `PostCandidate`, the core data structure filtered, including fields for author IDs, retweet sources, and quote references
- **[`home-mixer/models/query.rs`](https://github.com/xai-org/x-algorithm/blob/main/home-mixer/models/query.rs)** – Defines `ScoredPostsQuery`, which carries the `followed_user_ids` vector essential for the exemption logic

## Summary

- The `Brazil2026ElectionFilter` enforces Brazilian Electoral Resolution No. 23.610 by removing specific accounts from algorithmic recommendations during the 2026 election period.
- The filter references a static set of approximately 2,500 prohibited user IDs stored in `BRAZIL_2026_ELECTION_USER_IDS` within [`home-mixer/filters/brazil_2026_election_filter.rs`](https://github.com/xai-org/x-algorithm/blob/main/home-mixer/filters/brazil_2026_election_filter.rs).
- Content removal only occurs when the viewer does not follow the author, implementing the legal "follower exception" requirement.
- The `should_remove` method checks four relationship types: direct authorship, retweets, quotes, and reply ancestors to ensure comprehensive coverage.
- Unit tests verify that the filter maintains non-empty ID sets, correctly handles follow relationships, and properly processes retweet and quote metadata.

## Frequently Asked Questions

### What specific Brazilian law does the Brazil2026ElectionFilter enforce?

The filter implements **Electoral Resolution No. 23.610, Art. 28 §1º-A**, which mandates that platforms remove from algorithmic recommendations any content produced by accounts reported to the Superior Electoral Court (TSE) regarding the 2026 elections. The X-Algorithm codebase explicitly references this legal foundation in its documentation and implementation comments.

### How does the filter identify which accounts to remove?

The system maintains a static `LazyLock<FxHashSet<u64>>` named `BRAZIL_2026_ELECTION_USER_IDS` containing approximately 2,500 blacklisted user IDs. The `is_excluded_author` function performs O(1) hash set lookups to determine if a user ID requires filtering. This approach ensures minimal latency during the recommendation pipeline's execution while maintaining deterministic behavior based on the official electoral court data set.

### Why can users still see content from filtered accounts sometimes?

The implementation respects the **follow relationship exception** specified in Brazilian electoral law. The `should_remove` method explicitly checks the viewer's `followed_user_ids` vector before filtering. If a user follows an account listed in the prohibited set, that account's content remains visible in their recommendations. This architectural decision preserves user autonomy while complying with legal requirements regarding algorithmic amplification of unknown accounts.

### Where does the static list of prohibited IDs originate?

The `BRAZIL_2026_ELECTION_USER_IDS` set derives from the open data set of 2026 election candidates published by Brazilian electoral authorities. According to the source code in [`home-mixer/filters/brazil_2026_election_filter.rs`](https://github.com/xai-org/x-algorithm/blob/main/home-mixer/filters/brazil_2026_election_filter.rs), this list updates through the standard data pipeline processes and is loaded into memory via `LazyLock` to prevent repeated disk I/O during high-traffic recommendation requests.